【发布时间】:2013-11-16 08:02:53
【问题描述】:
我被创建UIView 应用CAGradientLayer 颜色效果作为我附加的图像波纹管。现在在这个我想改变它的渐变颜色从上到下平滑地改变,就像屏幕保护程序一样。我已经尝试使用 NStimer 那位 Done 但它在 CAGradientLayer 中的变化颜色看起来像混蛋。
对于上面我使用了 Bellow 的代码方法:-
Timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(TIMER) userInfo:nil repeats:NO];
-(void)TIMER
{
Count++;
[view_Color1 removeFromSuperview];
view_Color1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 341)];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = self.view_Color.bounds;
if (Count == 1)
{
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor greenColor] CGColor], (id)[[UIColor colorWithRed:44/255.0 green:255/255.0 blue:255/255.0 alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:0/255.0 green:0/255.0 blue:254/255.0 alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:252/255.0 green:0/255.0 blue:255/255.0 alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:252/255.0 green:0/255.0 blue:6/255.0 alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:253/255.0 green:131/255.0 blue:6/255.0 alpha:1.0f]CGColor], (id)[[UIColor colorWithRed:255/255.0 green:237/255.0 blue:10/255.0 alpha:1.0f]CGColor], nil];
}
else if (Count == 2)
{
gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:255/255.0 green:237/255.0 blue:10/255.0 alpha:1.0f]CGColor],(id)[[UIColor greenColor] CGColor], (id)[[UIColor colorWithRed:44/255.0 green:255/255.0 blue:255/255.0 alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:0/255.0 green:0/255.0 blue:254/255.0 alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:252/255.0 green:0/255.0 blue:255/255.0 alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:252/255.0 green:0/255.0 blue:6/255.0 alpha:1.0f] CGColor], (id)[[UIColor colorWithRed:253/255.0 green:131/255.0 blue:6/255.0 alpha:1.0f]CGColor],nil];
}
//and so on still count is 7 then again its 1 to continue here are count use for chagen 7 color gradient use and repeat.
[self.view addSubview:view_Color1];
[self.view_Color1.layer addSublayer:gradient];
[myappdelegare sharedinstance].str_LastColorClick = [[NSString alloc]initWithFormat:@"MultiColor"];
Timer = [NSTimer scheduledTimerWithTimeInterval:0.30 target:self selector:@selector(TIMER) userInfo:nil repeats:NO];
}
你能帮帮我吗?
谢谢
【问题讨论】:
-
不流畅,因为您每秒只渲染 10/3 帧。将时间间隔更改为 0.04 (25 fps)。
-
它在 0.04 中也出现了抖动。感谢您的帮助
标签: ios iphone objective-c uiview cagradientlayer