i want change colour of view while swiping don't know how animated colour change. i'll grateful help.
work calayer, if search find lot's of easy examples, 1 example, ray wenderlich, find great.
uiview
- (void)changecolorwithfillinganimation { //we create view increase in size top bottom, thats why starts these frame parameters uiview *fillingview = [[uiview alloc] initwithframe:cgrectmake(0, self.view.bounds.size.height - 1, self.view.bounds.size.width, 1)]; //set color want change fillingview.backgroundcolor = [uicolor bluecolor]; //add view want change color [self.view addsubview:fillingview]; [uiview animatewithduration:2.0 animations:^{ //this make view animates up, since animating frame target view's size fillingview.frame = self.view.bounds; } completion:^(bool finished) { //set color want , disappear filling view. self.view.backgroundcolor = [uicolor bluecolor]; [fillingview removefromsuperview]; }]; }
cashapelayer + cabasicanimation + catransition
- (void)changecolorwithshapelayer { //create initial , final path. uibezierpath *frompath = [uibezierpath bezierpathwithrect:cgrectmake(0, self.view.bounds.size.height - 1, self.view.bounds.size.width, 1)]; uibezierpath *topath = [uibezierpath bezierpathwithrect:cgrectmake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; //create shape layer animated cashapelayer *fillingshape = [cashapelayer layer]; fillingshape.path = frompath.cgpath; fillingshape.fillcolor = [uicolor bluecolor].cgcolor; //create animation shape layer cabasicanimation *animatedfill = [cabasicanimation animationwithkeypath:@"path"]; animatedfill.duration = 2.0f; animatedfill.fromvalue = (id)frompath.cgpath; animatedfill.tovalue = (id)topath.cgpath; //using catransaction can set completion block [catransaction begin]; [catransaction setcompletionblock:^{ //when animation ends, want set proper color itself! self.view.backgroundcolor = [uicolor bluecolor]; }]; //add animation shape layer, add shape layer sublayer on view changing color [fillingshape addanimation:animatedfill forkey:@"path"]; [self.view.layer addsublayer:fillingshape]; [catransaction commit]; }
one simple way accomplish use uiview animation block.
[uiview animatewithduration:1.0 animations:^{ view.backgroundcolor = [uicolor redcolor]; }];
Comments
Post a Comment