//
// ViewController.m
// 自动布局01
//
// Created by 唐帅 on 16/4/16.
// Copyright © 2016年 tang. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic,weak)UIView *blueView;
@property(nonatomic,weak)UIView *redView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIView *blueView = [[UIView alloc]init];
blueView.backgroundColor = [UIColor blueColor];
blueView.frame = CGRectMake(100, 100, 100, 100);
self.blueView = blueView;
[self.view addSubview:blueView];
UIView *redView = [[UIView alloc]init];
redView.backgroundColor = [UIColor redColor];
redView.frame = CGRectMake(25, 25, 50, 50);
self.redView = redView;
[blueView addSubview:redView];
// 给红色view添加约束
// UIViewAutoresizingNone = 0,
// UIViewAutoresizingFlexibleLeftMargin = 1 << 0,
// UIViewAutoresizingFlexibleRightMargin = 1 << 2,
// UIViewAutoresizingFlexibleTopMargin = 1 << 3,
// UIViewAutoresizingFlexibleBottomMargin = 1 << 5
//让红色的view向右下跟随蓝色view移动
self.redView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleTopMargin;
}
//触摸屏幕发生的事件
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
CGRect bounds = self.blueView.bounds;
bounds.size.width += 50;
bounds.size.height += 50;
self.blueView.bounds = bounds;
NSLog(@"%@",NSStringFromCGRect(self.blueView.bounds));
}
@end