1 #import "ViewController.h"2 3 #defineKdelta 604 5 @interfaceViewcontroller ()6 7 @end8 9 @implementationViewcontrollerTen One #pragmaMark encapsulates the code for the animation effect A- (void) Btnclickwithblock: (void(^) ()) Block - { - //Implementing animations (progressive changes) the [UIView Beginanimations:nil context:nil]; -[UIView setanimationduration:1.0]; - - block (); + - [UIView commitanimations]; + } A at //Cgaffinetransform Transform - //represents the deformation state of a space (rotation angle, scale) - #pragmaMark reverts to its original state --(ibaction) Reset: (ID) Sender { - -[Self btnclickwithblock:^{ in_btn.transform =cgaffinetransformidentity; - }]; to } + - #pragmaThe left and right rotation of the mark control button the-(ibaction) Rotate: (ID) Sender { * //tag can be used to distinguish the control $[Self btnclickwithblock:^{Panax Notoginsengcgfloat angle = [Sender tag]==Ten?0-M_pi_4:m_pi_4; -_btn.transform =cgaffinetransformrotate (_btn.transform, angle); the }]; + } A the #pragmaMark control buttons Move up and down +-(Ibaction) Run: (ID) Sender { - $[Self btnclickwithblock:^{ $CGRect ImageFrame =_btn.frame; -Nsinteger tag =[sender tag]; - Switch(tag) { the Case 1: -IMAGEFRAME.ORIGIN.Y-=Kdelta;Wuyi Break; the Case 2: -Imageframe.origin.x + =Kdelta; Wu Break; - Case 3: AboutIMAGEFRAME.ORIGIN.Y + =Kdelta; $ Break; - Case 4: -Imageframe.origin.x-=Kdelta; - Break; A + default: the Break; - } $_btn.frame =ImageFrame; the }]; the } the the #pragmaThe zoom of the Mark control button --(ibaction) Zoom: (ID) Sender { in the[Self btnclickwithblock:^{ theCGFloat scale = [Sender tag]== the?1.2:0.8; About_btn.transform =Cgaffinetransformscale (_btn.transform, scale, scale); the }]; the } the @end
Interface:
01-Achieve the zoom and animation effect of the image button (the initial application of block)