//
// Mjviewcontroller. m
// 10-uiview encapsulated Animation
//
// Created by Apple on 14-4-21.
// Copyright (c) 2014 itcast. All rights reserved.
//
# Import "mjviewcontroller. H"
@ Interface mjviewcontroller ()
@ Property (weak, nonatomic) iboutlet uiview * myview;
@ Property (weak, nonatomic) iboutlet uiimageview * iconview;
@ Property (nonatomic, assign) int index;
@ End
@ Implementation mjviewcontroller
-(Void) touchesbegan :( nsset *) touches withevent :( uievent *) event
{
Self. Index ++;
If (self. Index = 3 ){
Self. Index = 0;
}
Nsstring * filename = [nsstring stringwithformat: @ "mongod.jpg", self. index + 1];
Self. iconview. Image = [uiimage imagenamed: Filename];
// Execute the transition animation for the current view
[Uiview transitionwithview: Self. View Duration: 1.0 options: uiviewanimationoptiontransitionflipfromtop animations: Nil completion: Nil];
}
/**
* Simple animation provided by uiview
*/
-(Void) testviewsimpleanim
{
[Uiview beginanimations: Nil context: Nil];
// After the animation is executed, the animation stop method of self is automatically called.
// [Uiview setanimationdelegate: Self]; // sets the animation proxy
// [Uiview setanimationdidstopselector: @ selector (animatestop)]; // After the animation is executed, the current controller's animatestop will be called
Self. myview. Center = cgpointmake (200,300 );
[Uiview commitanimations];
// Block Animation
[Uiview animatewithduration: 1.0 animations: ^ {
Self. myview. Center = cgpointmake (200,300 );
} Completion: ^ (bool finished) {// After the animation is executed, it will be in completion.
}];
}
/**
* Layer Animation
*/
-(Void) testlayeranim
{
Cabasicanimation * anim = [cabasicanimation animation];
Anim. keypath = @ "position ";
Anim. tovalue = [nsvalue valuewithcgpoint: cgpointmake (0, 0)];
Anim. duration= 2.0;
Anim. removedoncompletion = no;
Anim. fillmode = kcafillmodeforwards;
Anim. Delegate = self;
// Layer animation is an illusion. During the animation execution, the position attribute of the layer has never changed.
[Self. myview. layer addanimation: anim forkey: Nil];
// Self. myview. layer. Position = cgpointmake (0, 0)
}
-(Void) animationdidstop :( caanimation *) anim finished :( bool) Flag
{
Nslog (@ "% @", nsstringfromcgpoint (self. myview. layer. Position ));
}
@ End
Animation encapsulated by uiview