Uiview flip effect implementation
Http://blog.csdn.net/studyrecord/article/details/6440823
Create a view-based template project and add the following code to the viewcontroller file to implement the flip effect;
-(Void) viewdidload {
[Super viewdidload];
// View to be flipped
Uiview * parentview = [[uiview alloc] initwithframe: cgrectmake (0,150,320,200)];
Parentview. backgroundcolor = [uicolor yellowcolor];
Parentview. tag= 1000;
[Self. View addsubview: parentview];
}
// Declare the following action response function in the H header file
// Add a button to the XIB file. The response function is the following function.
// After running the program, click the button to see the flip Effect
-(Ibaction) actionfanzhuan {
// Obtain the device context of the current drawing
Cgcontextref context = uigraphicsgetcurrentcontext ();
// Start preparing the animation
[Uiview beginanimations: Nil context: Context];
// Set the animation curve. The translation is not accurate. For details, see the official documentation of apple.
[Uiview setanimationcurve: uiviewanimationcurveeaseinout];
// Set the animation duration
[Uiview setanimationduration: 1.0];
// Because no member variables are added to the viewcontroller class, use the following method to obtain the subview added by viewdidload.
Uiview * parentview = [self. View viewwithtag: 1000];
// Set the animation effect
[Uiview setanimationtransition: uiviewanimationtransitioncurldown forview: parentview cache: Yes]; // from top to bottom
// [Uiview setanimationtransition: uiviewanimationtransitioncurlup forview: parentview cache: Yes]; // from bottom to top
// [Uiview setanimationtransition: uiviewanimationtransitionflipfromleft forview: parentview cache: Yes]; // left to right
// [Uiview setanimationtransition: uiviewanimationtransitionflipfromright forview: parentview cache: Yes]; // right to left
// Set the animation delegate
[Uiview setanimationdelegate: Self];
// When the animation execution ends, execute the animationfinished method.
[Uiview setanimationdidstopselector: @ selector (animationfinished :)];
// Submit an animation
[Uiview commitanimations];
}
// Animation effect execution completed
-(Void) animationfinished: (ID) sender {
Nslog (@ "animationfinished! ");
}
Run the program and click the button to see the animation effect.
Now I have added two child views to the parentview for animation.
-(Void) viewdidload {
[Super viewdidload];
Uiview * parentview = [[uiview alloc] initwithframe: cgrectmake (0,150,320,200)];
Parentview. backgroundcolor = [uicolor yellowcolor];
Parentview. tag= 1000;
Uiimageview * image1 = [[uiimageview alloc] initwithframe: cgrectmake (50, 50,100,100)];
Image1.backgroundcolor = [uicolor redcolor];
Image1.tag= 1001;
Uiimageview * image2 = [[uiimageview alloc] initwithframe: cgrectmake (50, 50,100,100)];
Image2.backgroundcolor = [uicolor bluecolor];
Image2.tag = 1002;
[Parentview addsubview: image1];
[Parentview addsubview: image2];
[Self. View addsubview: parentview];
}
-(Ibaction) actionfanzhuan {
Cgcontextref context = uigraphicsgetcurrentcontext ();
[Uiview beginanimations: Nil context: Context];
[Uiview setanimationcurve: uiviewanimationcurveeaseinout];
[Uiview setanimationduration: 1.0];
Uiview * parentview = [self. View viewwithtag: 1000];
[Uiview setanimationtransition: uiviewanimationtransitioncurldown forview: parentview cache: Yes];
// [Uiview setanimationtransition: uiviewanimationtransitioncurlup forview: parentview cache: Yes];
// [Uiview setanimationtransition: uiviewanimationtransitionflipfromleft forview: parentview cache: Yes];
// [Uiview setanimationtransition: uiviewanimationtransitionflipfromright forview: parentview cache: Yes];
Nsinteger Purple = [[parentview subviews] indexofobject: [parentview viewwithtag: 1002];
Nsinteger maroon = [[parentview subviews] indexofobject: [parentview viewwithtag: 1001];
[Parentview exchangesubviewatindex: Purple withsubviewatindex: maroon];
[Uiview setanimationdelegate: Self];
[Uiview setanimationdidstopselector: @ selector (animationfinished :)];
[Uiview commitanimations];
}
-(Void) animationfinished: (ID) sender {
Nslog (@ "animationfinished! ");
}
In addition, I previously wrote the animation implementation code in viewdidload, but the animation effect was not consistent. It was originally executed in viewdidload.
Cgcontextref context = uigraphicsgetcurrentcontext ();
The pointer to the next context is 0.