gpt4 book ai didi

ios - TextView 。在离开屏幕时淡出顶部的文字,有点像星球大战

转载 作者:搜寻专家 更新时间:2023-10-31 22:59:27 25 4
gpt4 key购买 nike

当文本离开屏幕时,我试图淡出我的 TextView 的顶部。我希望它看起来有点像《星球大战》的制作人员名单,但要保持其宽度。我一直在使用这段代码,但它只会让我的屏幕变黑。

 if let containerView = textView.superview {
let gradient = CAGradientLayer(layer: containerView.layer)
gradient.frame = containerView.bounds
gradient.colors = [UIColor.clearColor().CGColor, UIColor.blueColor().CGColor]
gradient.startPoint = CGPoint(x: 0.0, y: 1.0)
gradient.endPoint = CGPoint(x: 0.0, y: 0.85)
containerView.layer.mask = gradient
}

最佳答案

我已经用一个第三方库实现了同样的功能。

请试试这个。 : https://github.com/somtd/SWScrollView

它正在转换 ScrollView 中的 TextView ,这里是相同的代码:

- (void)setupScrollPerspective
{
CATransform3D transform = CATransform3DIdentity;
//z distance
float distance = [[UIScreen mainScreen] bounds].size.height;
float ratio = [[UIScreen mainScreen] bounds].size.height/[[UIScreen mainScreen] bounds].size.height;
transform.m34 = - ratio / distance;
transform = CATransform3DRotate(transform, 60.0f * M_PI / 180.0f, 1.f, 0.0f, 0.0f);
self.layer.transform = transform;
self.layer.zPosition = distance * ratio;
self.layer.position = CGPointMake([[UIScreen mainScreen] bounds].size.width/2,
[[UIScreen mainScreen] bounds].size.height/3);
}

enter image description here

我希望你想要类似的东西......

关于ios - TextView 。在离开屏幕时淡出顶部的文字,有点像星球大战,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38998087/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com