iOS開發transform的使用


//

//  ViewController.m

//  18-transform的使用

 

 

#import "ViewController.h"

 

@interface ViewController ()

@property(nonatomic,assign)CGFloat ty;

 

- (IBAction)up:(id)sender;

- (IBAction)big;

- (IBAction)rotate;

- (IBAction)reset;

 

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

}

 

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

 

/**

 向上向下向左向右

 

 @param sender <#sender description#>

 */

- (IBAction)up:(id)sender {

    

//    NSLog(@"up");

    //通過父控件拿到按鈕

    //可以通過父類拿到子類

    UIButton *headBtn = (UIButton *)[self.view viewWithTag:10];

    //2 通過fransform讓頭像向上走

    //tx 水平方向移動的范圍

    //ty 豎直方向移動的范圍

    

    /**

     CGAffineTransformMakeTranslation

     使用這個方法進行設置,每次變化都是以原始值進行

     變化的

 

     @param 0 <#0 description#>

     @param -10 <#-10 description#>

     @return <#return value description#>

     */

    //方法1: 開辟成員變量耗性能

//    self.ty-= 10;

//    headBtn.transform = CGAffineTransformMakeTranslation(0, self.ty);

    

    /**

     方法2:

     CGAffineTransformTranslate

     使用這個方法每次都是以CGAffineTransform 值進行變化的

     @param t#> <#t#> description#>

     @param tx#> <#tx#> description#>

     @param ty#> <#ty#> description#>

     @return <#return value description#>

     

     */

    headBtn.transform = CGAffineTransformTranslate(headBtn.transform, 0, -10);

 

    

    

}

 

//放大 縮小

- (IBAction)big {

    [UIView beginAnimations:nil context:nil];

    [UIView setAnimationDuration:1.5];

    UIButton *headBtn = (UIButton *)[self.view viewWithTag:10];

    headBtn.transform = CGAffineTransformScale(headBtn.transform, 1.5, 1.5);

    [UIView commitAnimations];

}

 

/**

 旋轉

 */

- (IBAction)rotate {

    UIButton *headBtn = (UIButton *)[self.view viewWithTag:10];

    headBtn.transform = CGAffineTransformRotate(headBtn.transform, M_PI_4);

    

    

}

 

/**

 復位

 */

- (IBAction)reset {

    UIButton *headBtn = (UIButton *)[self.view viewWithTag:10];

    headBtn.transform = CGAffineTransformIdentity;

    

}

 

 

 

 

 

 

 

 

@end


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM