From Liu Xuefeng
In iOS development, if you use the Uinavigationcontroller, with the Storyboard+push mode segue, by default, you can directly implement the view switch effect of the left and right.
However, if you do not use Uinavigationcontroller, the segue is set to push, the operation will be directly error, and model mode segue only cover Vertical,flip Horizontal,cross There are 4 modes of dissolve and partial curl, no push mode.
If you want to use push mode in a custom view toggle animation, the only way is to set segue to custom and then customize the push animation.
The custom view toggle animation effect is implemented by deriving a class from Uistoryboardsegue and then -(void)perform animating itself in the method.
After many times Google, find a variety of implementations, after comparison found that the simplest and most reliable push animation implemented as follows:
-(void) perform{uiviewcontroller* Source = (Uiviewcontroller *) self. Sourceviewcontroller;uiviewcontroller* Destination = (Uiviewcontroller *) self. Destinationviewcontroller;CGRect sourceframe = Source. View. Frame;Sourceframe. Origin. x=-sourceframe. Size. Width;CGRect Destframe = Destination. View. Frame;Destframe. Origin. x= Destination. View. Frame. Size. Width;Destination. View. Frame= Destframe;Destframe. Origin. x=0;[Source. View. SuperviewAddsubview:destination. View];[UIView animatewithduration:.animations:^{Source. View. Frame= Sourceframe;Destination. View. Frame= Destframe;} completion:^ (BOOL finished) {[Source presentviewcontroller:destination Anim Ated:no Completion:nil];}];}
The above is the implementation of switching from right to left view animation, the key code is:
sourceFrame.origin.x = -sourceFrame.size.width;
And
destFrame.origin.x = destination.view.frame.size.width;
Move the old view to the left, and the new view starts at the right.
Finally, after the animation is finished, manually switch the current view to the new view:
[source presentViewController:destination animated:NO completion:nil];
Because the animation effect we have already implemented, so switch to the new view do not use the animation.
Simply modify the above code to implement a left-to-right push toggle Animation:
CGRect sourceframe = Source. View. Frame;Sourceframe. Origin. x= Sourceframe. Size. Width;CGRect Destframe = Destination. View. Frame;Destframe. Origin. x=-destination. View. Frame. Size. Width;Destination. View. Frame= Destframe;
Using the custom mode of the segue, you can achieve any switching animation effect, for simple non-3D animation, a few simple lines of code can be achieved.
IOS does not use Uinavigationcontroller to implement push animations