#pragma mark 向上走
- (IBAction)up
{
// 不允许直接修改 对象 的 结构体属性 的成员
// 允许直接 对象 的 结构体 属性
CGRect tempFrame = self.head.frame;
tempFrame.origin.y -= 10;
self.head.frame = tempFrame;
- (IBAction)up
{
// 不允许直接修改 对象 的 结构体属性 的成员
// 允许直接 对象 的 结构体 属性
CGRect tempFrame = self.head.frame;
tempFrame.origin.y -= 10;
self.head.frame = tempFrame;
}
#pragma mark 放大
- (IBAction)big;
{
// 1.取出原来的属性
CGRect tempFrame = self.head.frame;
// 2.改变临时属性
tempFrame.size.width += 20;
tempFrame.size.height += 20;
// 3.用临时属性覆盖原来的属性
self.head.frame = tempFrame;
- (IBAction)big;
{
// 1.取出原来的属性
CGRect tempFrame = self.head.frame;
// 2.改变临时属性
tempFrame.size.width += 20;
tempFrame.size.height += 20;
// 3.用临时属性覆盖原来的属性
self.head.frame = tempFrame;
}
-
通过修改控件的frame属性就可以修改控件在屏幕上的位置和尺寸
-
比如点击“向上”按钮,让按钮的y值减小即可
- (IBAction)top:(UIButton*)sender {
CGRectbtnFrame = self.headBtn.frame;
btnFrame.origin.y -= 10;
self.headBtn.frame = btnFrame;
}
-
下面代码是错误的,OC语法规定:不允许直接修改对象的结构体属性的成员
self.headBtn.frame.origin.y -= 10;