大佬教程收集整理的这篇文章主要介绍了ios – 单个UIView上的多个同时UIViewAnimations,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
本质上,我想要一个UIView垂直动画,同时水平动画.因为我正在使用UIViewAnimationOptionRepeat,所以我无法在onCompletion中嵌套任何其他动画:这是我想要的工作,但不是:
[UIView animateWithDuration:duration delay:kANIMATION_DELAY options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{ object.frame = CGRectMake(object.frame.origin.x + 40,object.frame.origin.y,object.frame.size.width,object.frame.size.height); [UIView animateWithDuration:duration delay:kANIMATION_DELAY options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse animations:^{ object.frame = CGRectMake(object.frame.origin.x,object.frame.origin.y - 40,object.frame.size.height); } completion:^(BOOL finished) { }]; } completion:^(BOOL finished) { }];
UIView *view = views[i]; // Add the horizontal animation CABasicAnimation *horizontal = [CABasicAnimation animationWithKeyPath:@"position.x"]; horizontal.delegate = self; horizontal.fromValue = [NSnumber numberWithFloat:25.0]; horizontal.toValue = [NSnumber numberWithFloat:50.0]; horizontal.repeatCount = INFINITY; horizontal.duration = 6; horizontal.autoreverses = YES; horizontal.beginTime = 0; // ignore delay time for Now horizontal.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaSEOut]; [view.layer addAnimation:horizontal forKey:@"horizontal_animation"]; // Add the vertical animation CABasicAnimation *vertical = [CABasicAnimation animationWithKeyPath:@"position.y"]; vertical.delegate = self; vertical.fromValue = [NSnumber numberWithFloat:100.0]; vertical.toValue = [NSnumber numberWithFloat:400.0]; vertical.repeatCount = INFINITY; vertical.duration = 2; vertical.autoreverses = YES; vertical.beginTime = 0; // ignore delay time for Now vertical.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; [view.layer addAnimation:vertical forKey:@"vertical_animation"];
这允许我在两个单独的动画中处理重复,持续时间等.然后,当我的动画结束时,我可以调用follow方法来删除动画.要么,
[view.layer removeAllAnimations];
或者,如果我想删除更具体的动画,
[view.layer removeAnimationForKey:@"vertical_animation"];
然后,如果您想要在动画开始/停止时进行更多自定义控制,您只需要添加委托方法,如下所示:
-(void)animationDidStart:(CAAnimation *)anim { // custom code here } -(void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag { // custom code here }
它非常甜蜜和容易.希望这有助于任何有类似需求的人.干杯!
以上是大佬教程为你收集整理的ios – 单个UIView上的多个同时UIViewAnimations全部内容,希望文章能够帮你解决ios – 单个UIView上的多个同时UIViewAnimations所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。