1、IBAction和IBOutlet:
IBAction == voidIBAction只能用于方法,不能用于属性
IBOutlet由于声明属性中使用
2、控件属性
UI控件属性,苹果官方推荐weak3、frame和bounds:
frame
@property(nonatomic)CGRect frame;
空间所在矩形框的位置和尺寸(以父控件的左上角为坐标原点)
bounds
@property(nonatomic) CGRect bounds;
控件所在矩形框的位置和尺寸(以自己左上角为坐标原点,所以bounds的x和y一般为0)
4、修改frame中的属性:
下面一句为错:_btn.frame.origin.y -= 10;
OC语法规定:不允许直接修改某个对象结构体属性的成员
想修改的话要对整体进行修改
CGRect newFrame = _btn.frame;
newFrame.origin.y -= 10;
_btn.frame = newFrame;
5、添加动画:
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
中间写自己的代码
[UIView commitAnimations];
6、transform属性
_btn.transform = CGAffineTransformMakeRotation(- M_PI_4);
这里的意思是,btn按钮逆时针旋转45度,但是执行是没有效果的,因为它每次都赋值45度,
这个形变属性不会在你上次的基础上赋值,而是赋值你现在是多少度,每次点击都赋值45度,
所以不会出现旋转的特效,再点击第一次旋转后就不会再动了。
_btn.transform = CGAffineTransformRotate(_btn.transform, -M_PI_4);
这个方法是,在_btn.transform的形变基础上累加一个角度-M_PI_4。
相应的缩放的方法:CGAffineTransformMakeScale();
和CGAffineTransformScale();也类似于旋转。
7、使用block传递信息处理过程(相当于传递方法)
-(void)btnClickWithBlock:(void (^)())block {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
block();
[UIView commitAnimations];
}
-(IBAction)rotate:(id)sender {
[self btnClickWithBlock:^{
CGFloat scale = [sender tag] == 20 ? 1.2 : 0.8;
_ btn.transform = CGAffineTransformScale(_btn.transform, scale, scale);
}];
}
当遇到头尾都一样只有中间数据处理不一样的情况就可以用这种代码重构的方法。
8、使对象的transform恢复原状
transform有一个常量CGAffineTransformIdentity,这个常量代表的结构体直接赋值给transform,这样一赋值就会变成单位矩阵,即清空之前的所有transform