我正试图淡出文本视图的顶部,因为文本会从屏幕上消失。我希望它看起来有点像星球大战的积分但保持宽度。我一直在使用这段代码,但它只是将我的屏幕变黑。
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
}
答案 0 :(得分:1)
我已经使用一个第三方库实现了相同的功能。
请尝试这个。 :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);
}
我希望你想要类似的东西......