AutoresizingMask 的使用
(1)先了解一下这几个枚举值的含义:
(2)代码演说:
在viewcontroller 用代码创建一个红色的view,如下:
UIView *redView = [[UIView alloc] init];
redView.backgroundColor = [UIColor redColor];
CGFloat marginX = self.view.frame.size.width - ;
CGFloat marginY = self.view.frame.size.height - ;
redView.frame = CGRectMake(marginX, marginY, , );
[self.view addSubview:redView];
运行完后的效果图如下:
让手机横屏显示后的效果如下:
红色的视图看不到了,因为横屏显示后,并没有重新给redView这个视图重新布局;但是如果加上AutoresingMask后,代码如下:
UIView *redView = [[UIView alloc] init];
redView.backgroundColor = [UIColor redColor];
CGFloat marginX = self.view.frame.size.width - ;
CGFloat marginY = self.view.frame.size.height - ;
redView.frame = CGRectMake(marginX, marginY, , );
[self.view addSubview:redView]; redView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
运行的后,切换横屏的效果如下:
redView这个视图不仅固定在底部,而且还根据屏幕的宽度修改了redView的宽度。
但是antoresizing只能解决父控件与子控件之间的相对关系。
AutoresizingMask 的使用的更多相关文章
- 关于UIView的AutoresizingMask属性的研究
在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. 1 2 3 4 5 6 7 8 9 enum ...
- iOS -- autoResizingMask使用(转)
autoResizingMask 是UIView的一个属性,在一些简单的布局中,使用autoResizingMask,可以实现子控件相对于父控件的自动布局. autoResizingMask 是UIV ...
- UIView的autoresizingMask和autoresizesSubviews属性的剖析
UIVIew的autoresizingMask和autoresizesSubviews属性的剖析 autoresizingMask是为了iPad开发中横竖屏适配而降生的,他只能约束父子控件之间的关系. ...
- 自动布局之autoresizingMask使用详解(Storyboard&Code)
自动布局之autoresizingMask使用详解(Storyboard&Code) http://www.cocoachina.com/ios/20141216/10652.html 必须禁 ...
- ios 中的autoresizingMask
以前对这个知识理解的不太对,看了下面这个地址的文章后,感觉说的对,也没检验,今天实验后,发现是错的...在这里对以前读过此文的朋友表示抱歉. 原文地址如下: http://www.cnblogs.co ...
- IOS - 控件的AutoresizingMask属性
在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. enum { UIViewAutoresi ...
- UIView 的autoresizingMask属性
autoresizingMask属性的意思就是自动调整子控件与父控件中间的位置,宽高,定义如下: typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) ...
- 关于UIView的autoresizingMask属性的研究【转】
在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. 1 2 3 4 5 6 7 8 9 enum ...
- UIView的autoresizingMask属性
今天做相册列表的时候,发现有些 UITableViewController 属性不好记忆,然后就查找了一些资料.做一下备份. 在 UIView 中有一个autoresizingMask的属性,它对应的 ...
- 遇到的 autoresizingMask 相关的问题
1.前言 当一个控件设置好 frame,然后出现会 frame 显示不准或是跟随父控件的变化而变化了,你就要考虑是否是 autoresizing 的问题了 当在 xib 中布局时,报 NSAutore ...
随机推荐
- logstash收集系统日志配置
查看官方文档 https://www.elastic.co/guide/en/logstash/current/plugins-inputs-file.html 找个路径 /home/data/log ...
- ansible错误ImportError: No module named ansible.runner记录
按着官网提供的安装ansible To configure the PPA on your machine and install ansible run these commands: $ sudo ...
- 爬虫scrapy模块
首先下载scrapy模块 这里有惊喜 https://www.cnblogs.com/bobo-zhang/p/10068997.html 创建一个scrapy文件 首先在终端找到一个文件夹 输入 s ...
- Html学习之十(CSS选择器的使用--伪类选择器)
伪类选择器 一.基于a标签. 1.:hover 选择鼠标滑过的超链接元素 2.:active 选择鼠标单击中的超链接元素 3.:link 选择未被访问的超链接元素 4.:visited 选择已经被访问 ...
- jQuery的配置。
在python中有提前定义模板的功能,所以提前将jQuery的导入语句导入就可以直接使用jQuery语法: 一.下载jQuery包. 下载官网: https://jquery.com/ 可下载迷你版的 ...
- Python文件读取中:f.seek(0)和f.seek(0,0)有什么区别
file.seek()方法标准格式是:seek(offset,whence=0)offset:开始的偏移量,也就是代表需要移动偏移的字节数whence:给offset参数一个定义,表示要从哪个位置开始 ...
- BZOJ1688 「USACO05OPEN」Disease Manangement 背包+状压DP
问题描述 BZOJ1688 题解 背包,在转移过程中使用状压. \(\mathrm{Code}\) #include<bits/stdc++.h> using namespace std; ...
- Django2.2报错 AttributeError: 'str' object has no attribute 'decode'
准备将 Django 连接到 MySQL,在命令行输入命令 python manage.py makemigrations 后报错: AttributeError: 'str' object has ...
- react细节
1.在函数式组件中使用 类型和默认值 function App({ name }) { return ( <div> <h1>{name}</h1> </di ...
- python实现定时任务那些你不知道的模块
一.使用time中的sleep 这种方式最简单,在循环里放入要执行的任务,然后sleep一段时间在执行 from datetime import datetime import time # 每n秒执 ...