how can i do UIView animateWithDuration in viewDid

2019-07-20 07:32发布

I try this in viewDidAppear but i have a one second of delay =( what can i do? for work in 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"];


}

2条回答
别忘想泡老子
2楼-- · 2019-07-20 07:56

You shouldn't do any animation in viewDidLoad as the view won't have a superview yet so the animation is irrelevant.

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.

  • Using Core Animation within an animation block isn't necessary. 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.

  • In iOS 5+ you can use a custom container controller to present a child view controller with a defined animation.

  • In iOS 7 you can use 'presentViewController:animated:completion' and specify a custom animation. You would then set the transitioningDelegate property and have the delegate provide the animator for the transition.

I don't have ready sample code for the above but that's what I would look at.

查看更多
地球回转人心会变
3楼-- · 2019-07-20 08:12

Try to split Your animation by two 180 degree rotations. Seems that iOS 7 is lazy and wan't rotate by 360 :)

查看更多
登录 后发表回答