ios - Change Animation Speed Series of Images -
i have series of images, want them repeat. however, want first half play in, example 2 seconds, second half play in 5 seconds.
it quite easy play series of images, using following
- (void) completecycles:(int) cycles inhalepercentage:(int) inhalepercent exhalepercentage:(int) exhalepercent totalcycletime:(int) time { nsmutablearray *textures = [nsmutablearray array]; (int = 0; < knumberbreathingimages; i++) { nsstring *texturename = [nsstring stringwithformat:@"breath%d.png", i]; (int = 0; < inhalepercent; i++) { [textures addobject:[uiimage imagenamed:texturename]]; } } (int = knumberbreathingimages - 1; > 0; i--) { nsstring *texturename = [nsstring stringwithformat:@"breath%d.png", i]; (int = 0; < exhalepercent; i++) { [textures addobject:[uiimage imagenamed:texturename]]; } } self.animationimageview.animationimages = textures; self.animationimageview.animationduration = time; self.animationimageview.animationrepeatcount = cycles; [self.animationimageview startanimating]; }
however, want first half of animation take x time , second half take y time.
i don't think above allow me this, wondering better approach be.
pretty sure need use
uiview animatewithduration:animations: completion:
thanks assistance.
this code creates effect,
the animation system on uiimageview limited. suggest make own implementation 2 image view.
you change image in 1 imageview , fade in , out using uiview animatewithduration
i have written method you. please note: have not tested it.
it assumes have frames in array called 'frames' , have 2 uiimageview placed on top of each other called 'imgv1' , 'imgv2'
-(void)performanimationofframeatindex:(nsnumber*)indexnum { int index = [indexnum intvalue]; if(index >= frames.count) { return; } uiimage *img = [frames objectatindex:index]; uiimageview *imgin; uiimageview *imgout; if(index % 2 == 0) { imgin = imgv1; imgout = imgv2; } else { imgin = imgv2; imgout = imgv1; } imgin.image = img; [self.view sendsubviewtoback:imgin]; [uiview animatewithduration:0.1 animations:^ { imgin.alpha = 1; imgout.alpha = 0; } completion:^(bool finished) { [self performselectoronmainthread:@selector(performanimationofframeatindex:) withobject:[nsnumber numberwithint:index+1] waituntildone:no]; }]; }
thanks idea,
i changed code above desired effect wanted, works perfect. alpha causing "strobe" effect when duration 0 seconds.
here final code
enjoy 100 :-)
- (void) performanimationofframeatindex:(nsnumber*)indexnum { int index = indexnum.intvalue; if (index >= self.frames.count) return; uiimage *img = self.frames[index]; uiimageview *imgin; uiimageview *imgout; float speed = (index <= self.frames.count / 2) ? 0.1 : 1; // first half : second half speed. if (index % 2 == 0) { imgin = self.animationimageviewone; imgout = self.animationimageviewtwo; } else { imgin = self.animationimageviewtwo; imgout = self.animationimageviewone; } imgin.image = img; [self.view sendsubviewtoback:imgin]; [self performselector:@selector(performanimationofframeatindex:) withobject:[nsnumber numberwithint:index+1] afterdelay:speed]; }
Comments
Post a Comment