我怎么能在viewDidLoad做UIView animateWithDuration? IOS 7

我尝试在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"]; } 

你不应该在viewDidLoad做任何animation,因为视图还没有超级视图,所以animation是不相关的。

关于你的代码示例的一些想法:

  • 只要您希望每次显示视图时都使用viewDidAppear ,而不仅仅是第一次显示该视图。

  • 在animation块中使用Core Animation是没有必要的。 做一个或另一个。

build议

如果您试图为由不同的视图控制器pipe理的视图的外观设置animation,则呈现控制器负责animation。 有几种方法来实现这取决于你的最低支持版本的iOS。

  • 在iOS 5 +中,您可以使用自定义容器控制器来呈现具有定义的animation的子视图控制器。

  • 在iOS 7中,您可以使用“presentViewController:animated:completion”并指定一个自定义animation。 然后,您将设置transitioningDelegate属性,并让委托为过渡提供animation。

我没有准备好上面的示例代码,但这就是我所看到的。

试着将你的animation分成两个180度旋转。 看来,iOS 7是懒惰的,不会被360旋转:)