简体   繁体   English

如何在viewDidLoad中执行UIView animateWithDuration? IOS 7

[英]how can i do UIView animateWithDuration in viewDidLoad? ios7

I try this in viewDidAppear but i have a one second of delay =( what can i do? for work in viewDidLoad? 我在viewDidAppear中尝试此操作,但是我有一秒钟的延迟=(我该怎么办?在viewDidLoad中工作?

-(void)viewDidAppear:(BOOL)animated{


            fullRotation = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
            fullRotation.fromValue = [NSNumber numberWithFloat:0];
            fullRotation.toValue = [NSNumber numberWithFloat:((720*M_PI)/360)];
            fullRotation.duration = 5;
            //  fullRotation.repeatCount = 1e10f;
            [_propImaCirculoCompleto.layer addAnimation:fullRotation forKey:@"360"];


}

You shouldn't do any animation in viewDidLoad as the view won't have a superview yet so the animation is irrelevant. 您不应在viewDidLoad进行任何动画处理,因为该视图尚无超级视图,因此该动画无关紧要。

A few thoughts on your code sample: 对您的代码示例的几点思考:

  • You can use viewDidAppear as long as you want the animation every time the view appears, not just the first time it is presented. 您可以使用viewDidAppear ,只要每次视图出现时都需要动画即可,而不仅仅是在第一次出现时。

  • Using Core Animation within an animation block isn't necessary. 不需要在动画块中使用Core Animation。 Do one or the other. 做一个或另一个。

Suggestions 建议

If you are trying to animate the appearance of a view managed by a different view controller, the presenting controller is responsible for the animation. 如果您要对由其他视图控制器管理的视图的外观进行动画处理,则呈现控制器负责动画。 There are a few ways to implement this depending on your minimum supported version of iOS. 有几种方法可以实现此功能,具体取决于您的最低iOS支持版本。

  • In iOS 5+ you can use a custom container controller to present a child view controller with a defined animation. 在iOS 5+中,您可以使用自定义容器控制器向子视图控制器显示已定义的动画。

  • In iOS 7 you can use 'presentViewController:animated:completion' and specify a custom animation. 在iOS 7中,您可以使用'presentViewController:animated:completion'并指定自定义动画。 You would then set the transitioningDelegate property and have the delegate provide the animator for the transition. 然后,您将设置transitioningDelegate属性,并让委托为过渡提供动画效果。

I don't have ready sample code for the above but that's what I would look at. 我还没有准备好上面的示例代码,但这就是我要看的。

Try to split Your animation by two 180 degree rotations. 尝试将动画分成两个180度旋转。 Seems that iOS 7 is lazy and wan't rotate by 360 :) 似乎iOS 7是惰性的并且不会360度旋转:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM