gpt4 book ai didi

ios - layer.mask 渐变在 iOS7 中是 Solid

转载 作者:行者123 更新时间:2023-11-28 22:24:25 25 4
gpt4 key购买 nike

下一个代码在 ios6 中运行良好。它应该将顶部和底部的内部 alpha 渐变应用于 View :

CAGradientLayer * gradient = [CAGradientLayer layer];
gradient.frame = self.bounds;
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor clearColor] CGColor],
(id)[[UIColor whiteColor]CGColor],
(id)[[UIColor whiteColor]CGColor],
(id)[[UIColor clearColor] CGColor],
nil];

gradient.startPoint = CGPointMake(0.5, 0.0);
gradient.endPoint = CGPointMake(0.5, 1.0);
gradient.locations = [NSArray arrayWithObjects:@0,@(val),@(1.-val),@1,nil];

self.layer.mask = gradient;

但是!如果我在 iOS7 中运行此代码,而不是漂亮的混合 alpha 渐变,渐变的“透明”部分是纯白色。

最佳答案

我会把它放在评论中,但格式会被关闭。这段代码适用于 iOS 7。您可以根据自己的需要进行调整。如果它仍然不起作用,那么我会说渐变不是问题。

+(void)addScrollingGradientToView:(UIView*)view
{
//add in the gradient to show scrolling
CAGradientLayer *nextImageFade = [CAGradientLayer layer];
nextImageFade.frame = CGRectInset(view.bounds,-10,-10);

nextImageFade.colors = [NSArray arrayWithObjects:(id)[UIColor colorWithRed:0. green:0. blue:0. alpha:0.].CGColor,
[UIColor colorWithRed:0. green:0. blue:0. alpha:1.0].CGColor,
[UIColor colorWithRed:0. green:0. blue:0. alpha:1.0].CGColor,
[UIColor colorWithRed:0. green:0. blue:0. alpha:0.0].CGColor,nil];
nextImageFade.locations = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:20 / view.frame.size.height],
[NSNumber numberWithFloat:(view.frame.size.height - 20) / view.frame.size.height],
[NSNumber numberWithFloat:1.], nil];
nextImageFade.startPoint = CGPointMake(.5, 0);
nextImageFade.endPoint = CGPointMake(.5, 1);

//Put in the fading last so that it is above everything else
[view.layer setMask:nextImageFade];
}

关于ios - layer.mask 渐变在 iOS7 中是 Solid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19384947/

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