码迷,mamicode.com
首页 > 移动开发 > 详细

iOS缩放、旋转UIButton

时间:2014-08-20 22:27:12      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:blog   os   io   for   div   cti   代码   log   

在练习缩放旋转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];
}

 

iOS缩放、旋转UIButton,布布扣,bubuko.com

iOS缩放、旋转UIButton

标签:blog   os   io   for   div   cti   代码   log   

原文地址:http://www.cnblogs.com/qifeng/p/3925537.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!