@interface HomeViewController ()
@property (nonatomic,retain)UIView *redView;
@end
@implementation HomeViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
_redView = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
_redView.backgroundColor = [UIColor redColor];
[self.view addSubview:_redView];
UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 50, 50)];
blueView.backgroundColor = [UIColor blueColor];
[_redView addSubview:blueView];
//设置blueView属性
/*
外部四根线勾选
UIViewAutoresizingNone = 0,
左侧灵活,外部右侧线勾选
UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
宽度灵活,内部横向线勾选
UIViewAutoresizingFlexibleWidth = 1 << 1,
右侧灵活,外部左侧线勾选
UIViewAutoresizingFlexibleRightMargin = 1 << 2,
上部灵活,外部下侧线勾选
UIViewAutoresizingFlexibleTopMargin = 1 << 3,
高度灵活,内部纵向线勾选
UIViewAutoresizingFlexibleHeight = 1 << 4,
底部灵活,外部上侧线勾选
UIViewAutoresizingFlexibleBottomMargin = 1 << 5
*/
blueView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
/*
autoresizing 只能参照父类来设置 (了解)
与autolayout 是互斥的,不能并存
*/
}
//点击触发事件
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
CGRect redbounds = _redView.bounds;
redbounds.size.width += 20;
redbounds.size.height += 20;
_redView.bounds = redbounds;
}