@interface Viewcontroller () { *animationview; *button; Cgpoint AnimationPoint;} @end
Initialize the button and the view of the animation
- (void) viewdidload {[Super viewdidload]; Self.view.backgroundColor=[Uicolor Whitecolor]; //Create buttonbutton =[UIButton Buttonwithtype:uibuttontypesystem]; Button.layer.borderWidth=0.5f; Button.layer.cornerRadius=7.0f; Button.frame= CGRectMake ( -, -, -, -); [Button Settitle:@"Animation"Forstate:uicontrolstatenormal]; [Button addtarget:self action: @selector (ShowAnimation) forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:button]; //point at which animation zoom startsAnimationPoint = Cgpointmake (button.frame.origin.x + button.frame.size.width/2,0); //animated ViewAnimationview = [[UIView alloc] Initwithframe:cgrectmake ( -, BUTTON.FRAME.ORIGIN.Y + button.frame.size.height +Ten,280, -)]; Animationview.backgroundcolor=[Uicolor Graycolor]; AnimationView.layer.cornerRadius=7.0f; Animationview.alpha=0.0f; [Self.view Addsubview:animationview];}
How to deal with animations
- (void) showanimation {cgfloat OffsetX= Animationpoint.x-self.view.frame.size.width/2; CGFloat OffsetY= Animationpoint.y-animationview.frame.size.height/2; if(Animationview.alpha = =0.0f) { //animation changed from small to largeAnimationview.transform = Cgaffinetransformmake (0.01,0,0,0.01, OffsetX, OffsetY); [UIView animatewithduration:0.3fanimations:^{Animationview.alpha=1.0f; Animationview.transform= Cgaffinetransformmake (1.05f,0,0,1.0f,0,0); } Completion:^(BOOL finished) {[UIView animatewithduration:0.1fanimations:^{animationview.transform= Cgaffinetransformmake (1,0,0,1,0,0); } Completion:^(BOOL finished) {//Restore PositionAnimationview.transform =cgaffinetransformidentity; }]; }]; } Else { //animation changed from big to smallAnimationview.transform = Cgaffinetransformmake (1,0,0,1,0,0); [UIView animatewithduration:0.2animations:^{animationview.transform= Cgaffinetransformmake (0.01,0,0,0.01, OffsetX, OffsetY); } Completion:^(BOOL finished) {Animationview.transform=cgaffinetransformidentity; Animationview.alpha=0.0f; }]; } }
Animation
IOS UIView Simple scale animation