iOS縮放、旋轉UIButton


在練習縮放旋轉UIButton控件時,出現點擊控件x,y同時增加或者減一定像素,經過查找是xcode5開啟了Auto Layout.

放大縮小的代碼

- (IBAction)btnScale:(UIButton *)sender {
    //動畫開始,設置執行時間
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    int tag = [sender tag];
    float scale = tag == 8? 1.2: 0.8;
    //CGAffineTransform _transform = _btn.transform;
    _btn.transform = CGAffineTransformScale(_btn.transform, scale, scale);
    //_transform = _btn.transform;
    //提交動畫
    [UIView commitAnimations];
}

 左右旋轉的代碼

- (IBAction)btnRotate:(UIButton *)sender {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    int tag = [sender tag];
    int rotate = tag == 7? 1: -1;
    _btn.transform = CGAffineTransformRotate(_btn.transform, M_PI_4*rotate);
    //int rotate = tag==7? 1: -1;
    //_btn.transform = CGAffineTransformRotate(_btn.transform, M_PI_4*rotate);
    [UIView commitAnimations];
}

 還原控件的操作

- (IBAction)btnReset:(UIButton *)sender {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:1];
    sender.transform = CGAffineTransformIdentity;
    [UIView commitAnimations];
}

 


免責聲明!

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



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