01-scaling and animation effects of image buttons (initial application of block) and 01-block
1 # import "ViewController. h "2 3 # define kDelta 60 4 5 @ interface ViewController () 6 7 @ end 8 9 @ implementation ViewController10 11 # pragma mark code 12-(void) btnClickWithBlock :( void (^) () block13 {14 // implement animation (progressive change) 15 [UIView beginAnimations: nil context: nil]; 16 [UIView setAnimationDuration: 1.0]; 17 18 block (); 19 20 [UIView commitAnimations]; 21} 22 23 // CGAffineTransform transform24 // indicates space deformation Status (rotation angle, scaling ratio) 25 # pragma mark is restored to original status 26-(IBAction) reset :( id) sender {27 28 [self btnClickWithBlock: ^ {29 _ btn. transform = CGAffineTransformIdentity; 30}]; 31} 32 33 # Left and Right rotation of The pragma mark control button 34-(IBAction) rotate :( id) sender {35 // tag can be used to differentiate controls 36 [self btnClickWithBlock: ^ {37 CGFloat angle = [sender tag] = 10? 0-M_PI_4: M_PI_4; 38 _ btn. transform = CGAffineTransformRotate (_ btn. transform, angle); 39}]; 40} 41 42 # the left and right sides of the pragma mark control button move up and down 43-(IBAction) run :( id) sender {44 45 [self btnClickWithBlock: ^ {46 CGRect imageFrame = _ btn. frame; 47 NSInteger tag = [sender tag]; 48 switch (tag) {49 case :50 imageFrame. origin. y-= kDelta; 51 break; 52 case 2: 53 imageFrame. origin. x + = kDelta; 54 break; 55 case 3: 56 imageFrame. o Rigin. y + = kDelta; 57 break; 58 case 4: 59 imageFrame. origin. x-= kDelta; 60 break; 61 62 default: 63 break; 64} 65 _ btn. frame = imageFrame; 66}]; 67} 68 69 # zoom 70-(IBAction) zoom :( id) sender {71 72 [self btnClickWithBlock: ^ {73 CGFloat scale = [sender tag] = 15? 1.2: 0.8; 74 _ btn. transform = CGAffineTransformScale (_ btn. transform, scale, scale); 75}]; 76} 77 @ end
Interface: