01-scaling and animation effects of image buttons (initial application of block) and 01-block

Source: Internet
Author: User

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:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.