iOS View flip Animation Implementation-code old, for reference
Source: Internet
Author: User
<span id="Label3"></p><p><p>Create a new view-based template project, Add the following code in the Viewcontroller file, you can achieve the rollover effect;</p></p><p><p></p></p><p><p>-(void) Viewdidload {</p></p><p><p>[super viewdidload];</p></p><p><p>Views that need to be flipped</p></p><p><p>UIView *parentview = [[UIView alloc] initwithframe:cgrectmake (0, 150, 320, 200)];</p></p><p><p>Parentview.backgroundcolor = [uicolor yellowcolor];</p></p><p><p>Parentview.tag = 1000;</p></p><p><p></p></p><p><p>[self.view addsubview:parentview];</p></p><p><p>}</p></p><p><p></p></p><p><p>An action response function that needs to be declared below the H header file</p></p><p><p>Add a button to the Xib file whose response function is the following function</p></p><p><p>After running the program, click on the button to see the rollover effect</p></p><p><p>-(ibaction) actionfanzhuan{</p></p><p><p></p></p><p><p>Gets the device context for the current drawing</p></p><p><p>Cgcontextref context = Uigraphicsgetcurrentcontext ();</p></p><p><p></p></p><p><p>Start preparing animations</p></p><p><p>[UIView Beginanimations:nil context:context];</p></p><p><p></p></p><p><p>Set the animation curve, translation is not allowed, see Apple official documents</p></p><p><p>[UIView setanimationcurve:uiviewanimationcurveeaseinout];</p></p><p><p></p></p><p><p>Set the duration of an animation</p></p><p><p>[UIView setanimationduration:1.0];</p></p><p><p></p></p><p><p>Because no member variables are added to the Viewcontroller class, the following method is used to get the Sub-view Viewdidload added</p></p><p><p>UIView *parentview = [self.view viewwithtag:1000];</p></p><p><p></p></p><p><p>animating effects</p></p><p><p>[UIView Setanimationtransition:uiviewanimationtransitioncurldown Forview:parentview cache:yes]; From top to bottom</p></p><p><p>[UIView Setanimationtransition:uiviewanimationtransitioncurlup Forview:parentview cache:yes]; From bottom up</p></p><p><p>[UIView Setanimationtransition:uiviewanimationtransitionflipfromleft Forview:parentview cache:YES]; From left to right</p></p><p><p>[UIView setanimationtransition:uiviewanimationtransitionflipfromright Forview:parentview Cache:yes];//from right to left</p></p><p><p></p></p><p><p>Set Animation delegates</p></p><p><p>[UIView setanimationdelegate:self];</p></p><p><p></p></p><p><p>Executes the Animationfinished method when the animation execution is finished</p></p><p><p>[UIView setanimationdidstopselector: @selector (animationfinished:)];</p></p><p><p></p></p><p><p>Submit Animation</p></p><p><p>[UIView commitanimations];</p></p><p><p>}</p></p><p><p></p></p><p><p>Animation effect completed</p></p><p><p>-(void) animationfinished: (id) sender{</p></p><p><p>NSLog (@ "animationfinished!");</p></p><p><p>}</p></p><p><p></p></p><p><p>Run the program, click the button, you can see the animation effect</p></p><p><p></p></p><p><p>I've added two sub-views to the Parentview on my own. animate</p></p><p><p></p></p><p><p>-(void) Viewdidload {</p></p><p><p>[super viewdidload];</p></p><p><p>UIView *parentview = [[UIView alloc] initwithframe:cgrectmake (0, 150, 320, 200)];</p></p><p><p>Parentview.backgroundcolor = [uicolor yellowcolor];</p></p><p><p>Parentview.tag = 1000;</p></p><p><p></p></p><p><p>Uiimageview *image1 = [[uiimageview alloc] initwithframe:cgrectmake (50, 50, 100, 100)];</p></p><p><p>Image1.backgroundcolor = [uicolor redcolor];</p></p><p><p>Image1.tag = 1001;</p></p><p><p></p></p><p><p>Uiimageview *image2 = [[uiimageview alloc] initwithframe:cgrectmake (50, 50, 100, 100)];</p></p><p><p>Image2.backgroundcolor = [uicolor bluecolor];</p></p><p><p>Image2.tag = 1002;</p></p><p><p></p></p><p><p>[parentview addsubview:image1];</p></p><p><p>[parentview addsubview:image2];</p></p><p><p></p></p><p><p>[self.view addsubview:parentview];</p></p><p><p>}</p></p><p><p></p></p><p><p>-(ibaction) actionfanzhuan{</p></p><p><p>Cgcontextref context = Uigraphicsgetcurrentcontext ();</p></p><p><p>[UIView Beginanimations:nil context:context];</p></p><p><p>[UIView setanimationcurve:uiviewanimationcurveeaseinout];</p></p><p><p>[UIView setanimationduration:1.0];</p></p><p><p>UIView *parentview = [self.view viewwithtag:1000];</p></p><p><p></p></p><p><p>[UIView Setanimationtransition:uiviewanimationtransitioncurldown Forview:parentview cache:yes];</p></p><p><p>[UIView Setanimationtransition:uiviewanimationtransitioncurlup Forview:parentview cache:yes];</p></p><p><p>[UIView Setanimationtransition:uiviewanimationtransitionflipfromleft Forview:parentview cache:YES];</p></p><p><p>[UIView setanimationtransition:uiviewanimationtransitionflipfromright Forview:parentview cache:YES];</p></p><p><p></p></p><p><p>Nsinteger purple = [[parentview subviews] Indexofobject:[parentview viewwithtag:1002]];</p></p><p><p>Nsinteger maroon = [[parentview subviews] indexofobject:[parentview viewwithtag:1001]];</p></p><p><p>[parentview Exchangesubviewatindex:purple withsubviewatindex:maroon];</p></p><p><p></p></p><p><p>[UIView setanimationdelegate:self];</p></p><p><p>[UIView setanimationdidstopselector: @selector (animationfinished:)];</p></p><p><p></p></p><p><p>[UIView commitanimations];</p></p><p><p>}</p></p><p><p></p></p><p><p>-(void) animationfinished: (id) sender{</p></p><p><p>NSLog (@ "animationfinished!");</p></p><p><p>}</p></p><p><p></p></p><p><p>In Addition: before the viewdidload in the implementation of the code to implement the animation, but the same does not realize the animation effect, the original in the viewdidload inside the execution</p></p><p><p>Cgcontextref context = Uigraphicsgetcurrentcontext ();</p></p><p><p>The pointer to the back context is 0</p></p><p><p>iOS View flip Animation Implementation-code old, for reference</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service