
-(voID)movePic:(ID)sender{ for(int i = 0; i < self.array.count; i++){ CGPoint location = [[self.array objectAtIndex:i] CGPointValue]; [UIVIEw animateWithDuration:0.1 animations:^{ self.imageVIEw.center = location; } completion:^(BOol finished){ }]; }} 问题是for循环运行得非常快,所以你只能在最后几点看到动画.我不确定如何更好地设计这个.理想情况下,我可以做些什么来确保一个动画在另一个动画开始之前完成?我不应该使用for循环吗?谢谢
解决方法 您的代码假定UIVIEw动画在主线程中同步运行,而它们没有.你似乎有两个选择
>显式CAKeyframeAnimation,用于沿任意数量的采样点设置CALayer动画(在它们之间进行插值)
>隐式递归UIVIEw动画,用于沿一系列采样点动画UIVIEw(在它们之间插值)
前者会更有效率 – 我仍然认为我可以向你展示两种选择.
CAKeyframeAnimation
- (voID)movePic:(ID)sender{ //create a mutable core-graphics path CGMutablePathref path = CGPathCreateMutable(); for(int i = 0; i < self.array.count; i++) { CGPoint location = [[self.array objectAtIndex:index] CGPointValue]; CGPathAddlinetoPoint(path,nil,location.x,location.y); } //create a new keyframe animation CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"]; //add our path to it pathAnimation.path = path; //be nice to the system CGPathRelease(path); //setup some more animation parameters pathAnimation.duration = 0.1 * self.array.count; //add the animation to our imageVIEw's layer (which will start the animation) [self.imageVIEw.layer addAnimation:pathAnimation forKey:@"pathAnimation"];} UIVIEw动画
- (voID)movePictopointAtIndex:(unsigned int)index{ //safeguard check... if ([self.array count] <= index) return; //get the next location CGPoint location = [[self.array objectAtIndex:index] CGPointValue]; //animate the imageVIEw center towards that location [UIVIEw animateWithDuration:0.1 delay:0.0 options:UIVIEwAnimationoptionBeginFromCurrentState | UIVIEwAnimationoptionAllowUserInteraction animations:^{ self.imageVIEw.center = location; } completion:^(BOol finished){ //we are done with that animation,Now go to the next one... [self movePictopointAtIndex:index+1]; }];}- (voID)movePic:(ID)sender{ [self movePictopointAtIndex:0];} 总结 以上是内存溢出为你收集整理的iphone – 沿着一系列CGPoints移动图像全部内容,希望文章能够帮你解决iphone – 沿着一系列CGPoints移动图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)