ios - How to change background layer gradient color slowly for UIview? -
ios - How to change background layer gradient color slowly for UIview? -
in view did load method array loading different colors floating point.
- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. backgroundlayerone = [cagradientlayer gradientlayertwo]; backgroundlayerone.frame = self.view.bounds; [self.view.layer insertsublayer:backgroundlayerone atindex:0]; nsm_topx = [[nsmutablearray alloc]initwithobjects:@"0.17",@"0.36",@"0.93",@"0.93",nil]; nsm_bottomx = [[nsmutablearray alloc]initwithobjects:@"0.55",@"0.64",@"0.99",@"0.94",nil]; nsm_topy = [[nsmutablearray alloc]initwithobjects:@"0.62",@"0.63",@"0.50",@"0.10",nil]; nsm_bottomy = [[nsmutablearray alloc]initwithobjects:@"0.91",@"0.79",@"0.73",@"0.51",nil]; nsm_topz = [[nsmutablearray alloc]initwithobjects:@"0.64",@"0.54",@"0.07",@"0.38",nil]; nsm_bottomz = [[nsmutablearray alloc]initwithobjects:@"0.92",@"0.52",@"0.47",@"0.65",nil]; count=0; [self setupview]; }
setup view function phone call nstimer changiing color
-(void)setupview { [nstimer scheduledtimerwithtimeinterval:4.0 target:self selector:@selector(changebackgroundwithlayer) userinfo:nil repeats:yes]; }
this function changing background layer .
- (void)changebackgroundwithlayer { [backgroundlayerone removefromsuperlayer]; backgroundlayerone = nil; backgroundlayerone = [self gradientlayer]; backgroundlayerone.frame = self.view.bounds; [self.view.layer insertsublayer:backgroundlayerone atindex:0]; }
this function create gradient color layer.
- (cagradientlayer *)gradientlayer { float topx = [[nsm_topx objectatindex:count]floatvalue]; float topy = [[nsm_topy objectatindex:count]floatvalue]; float topz = [[nsm_topz objectatindex:count]floatvalue]; float bottomx = [[nsm_bottomx objectatindex:count]floatvalue]; float bottomy = [[nsm_bottomy objectatindex:count]floatvalue]; float bottomz = [[nsm_bottomz objectatindex:count]floatvalue]; uicolor *topcolor = [uicolor colorwithred:topx green:topy blue:topz alpha:1]; uicolor *bottomcolor = [uicolor colorwithred:bottomx green:bottomy blue:bottomz alpha:1]; nsarray *gradientcolors = [nsarray arraywithobjects:(id)topcolor.cgcolor, (id)bottomcolor.cgcolor, nil]; nsarray *gradientlocations = [nsarray arraywithobjects:[nsnumber numberwithint:0.0],[nsnumber numberwithint:1.0], nil]; cagradientlayer *gradientlayer = [cagradientlayer layer]; gradientlayer.colors = gradientcolors; gradientlayer.locations = gradientlocations; if(count < [nsm_topx count]-1) { count++; } else { count =0 ; } homecoming gradientlayer; }
this function work perfectly. question it's work fast color changes want alter color slowly.
how alter gradient color in layer slow animation?
ios ios7 uiview uiviewanimationtransition
Comments
Post a Comment