IOS学习 autoresizing 屏幕适配 父子视图
2016-03-22 23:31
393 查看
@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;
}
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;
}
相关文章推荐
- iOS web remote debug 正确的姿势
- iOS 自定义下载进度条
- IOS开发-ObjC-NSString
- iOS中常见的设计模式(MVC/单例/委托/观察者)
- MMDrawerController 与 StoryBoard 构建和谐抽屉效果
- 音效与音乐
- iOS加密方式及解压缩文件
- iOS一个项目开始创建, 部署到git服务器
- iOS开发-蓝牙模块
- iOS 截取字符串中汉字 —— HERO博客
- AFNetWorking 3.0请求返回NSData类型数据解决方案--iOS开发
- iOS 用到的宏
- iOS开发调试技巧
- iOS之08-核心语法
- 小画板demo
- iOS开发-系统自带的正则表达式
- iOS 如何自定义NavigationBar的高度
- iOS利用drawRect画图
- iOS开发:Xcode项目添加资源文件注意点
- iOS 页面间几种传值方式(属性,代理,block,单例,通知)