首页 > 代码库 > iOS缩放、旋转UIButton
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];}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。