- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章详解iOS应用开发中autoresizing尺寸自动适应属性的用法由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
前言:现在已经不像以前那样只有一个尺寸,现在最少的iphone开发需要最少需要适配三个尺寸。因此以前我们可以使用硬坐标去设定各个控件的位置,但是现在的话已经不可以了,我们需要去做适配,也许你说可以使用两套ui或两套以上的ui,但那样不高效也不符合设计。ios有两大自动布局利器:autoresizing 和 autolayout(autolayout是ios6以后新增)。autoresizing是uiview的属性,一直存在,使用也比较简单,但是没有autolayout那样强大。如果你的界面比较简单,要求的细节没有那么高,那么你完全可以使用autoresizing去进行自动布局。以下会针对autoresizing进行讨论.
零、autoresizing使用前的解释:
uiviewautoresizing是一个枚举类型,默认是uiviewautoresizingnone,也就是不做任何处理.
各属性解释:
。
在这里说明一下,如果是经常使用storyboard/xib设置autoresizing,那么转变使用代码设置autoresizing的话,容易出现理解错误问题。比如说uiviewautoresizingflexibletopmargin,也许会被误认为是顶部距离不变,其实是底部距离不变。这个解决办法也很简单,只需要把使用代码和使用storyboard设置autoresizing,它们是相反的,只需要这样去记就可以了.
autoresizing组合使用:
也就是枚举中的值可以使用|隔开,同时拥有多个值的功能,可以针对不同的场景作不同的变化。例如:
uiviewautoresizingflexiblewidth | uiviewautoresizingflexiblebottommargin 意思是:view的宽度按照父视图的宽度比例进行缩放,距离父视图顶部距离不变.
其它的组合类似,我这里就不一一列举了.
注意:
1)view的autoresizessubviews属性为yes时(默认为yes),autoresizing才会生效.
2)从xcode6开始,storyboard&xib默认是自动布局,因此我们需要手动调整,才能使用autoresizing.
具体操作如图(打开storyboard文件,你就会看到下面图的界面):
下面会写一个简单的例子以给予你们更直观的理解,并会在本文最后附上demo下载地址,请继续往下观看噢.
demo:
1)顶部距离父视图距离不变 。
2)宽度按父视图比例进行拉伸 。
3)view与父视图的左边距和右边距不变 。
1、使用代码(code)控制autoresizingmask 。
下面是项目用到的宏:
没有做适配之前的代码:
它将会显示:
。
使用autoresizing进行界面适配:
补充:你可以先按其它的设备尺寸为界面上的控件初始化,因为autoresizing是会以父视图的改变而改变.
最后显示:
。
2、在storyboard控制autoresizingmask 。
autoresizingmask无论是在storyboard中实现还是用代码实现,本质上来说就是六条线.
在storyboard中使用autoresizingmask需要将autolayout禁用掉.
如图:
。
图中共有六条线(上下左右到外围的距离线和内部的两条线).
如果上下左右的线中的某一条选中,则表示距离父控件的边界的距离不变.
比如图中选中左和上的线,表示蓝色view距离self.view的左边界和上边界的距离不变.
如果同时选中上下左右的线,那么行为会和选中上左的线是一样的,也就是默认的行为.
如果想让子控件尺寸跟随父控件尺寸改变而改变,那么需要用到内部的两条线。内部的线表示允许控件在水平和垂直方向上可拉伸。如果不选中内部的线,说明是不希望控件可拉伸的,也就是固定大小的.
也就是说,周围的线选中表示固定距离,内部的线选中表示允许拉伸.
如果用代码设置autoresizingmask,会发现一个view的autoresizingmask属性是一个枚举:
除了第一个是none,剩下的六个就对应storyboard中的六条线.
。
注意上面 。
这是正好和storyboard中设置autoresizingmask中内部的两天线是一致的:可拉伸的宽度和高度.
。
剩下的需要注意一下:
在storyboard中,如果选中周围的线,表示距离固定。比如我选中了左边的线,那么表示我想要左边的距离固定,所以在代码中我应该选择uiviewautoresizingflexiblerightmargin,即表示右边的距离不固定,那么则默认左边的距离固定.
。
autoresizingmask的缺点是只能保证父控件和子控件间的关系,无法保证同级控件间的关系,也就是说有些需求,autoresizingmask是无法实现的。更多的精力应该放在autolayout上.
最后此篇关于详解iOS应用开发中autoresizing尺寸自动适应属性的用法的文章就讲到这里了,如果你想了解更多关于详解iOS应用开发中autoresizing尺寸自动适应属性的用法的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我需要一些说明。我可以直接写入 /dev/port 以直接访问并行端口并且它工作正常(我可以打开插入端口连接器的 LED)。但是,我想我可以用 /dev/mem 做同样的事情? (http://tld
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我使用 Visual C++ 和 Win32 API 学习了 Windows 编程。如今,似乎大多数应用程序都是使用 C# 在 .NET 中开发的。我知道大多数时候 native 代码和托管代码之间没
请耐心等待。我正在制作一个 java 控制台,类似于此处找到的 DragonConsole https://code.google.com/p/dragonconsole/ 。一切都按计划进行,但我想
关闭。这个问题需要更多 focused .它目前不接受答案。 想要改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭5年前。 Improve this que
Django 的开发服务器表现得很奇怪。访问它的浏览器在加载时卡住,任何退出它的尝试都不起作用。当我点击 control c看似相当,但实际上仍在运行。让它退出的唯一方法是重新启动我的电脑,这很令人沮
我正在使用 Flash Develop,并且创建了一个 ActionScript 3.0 项目。它启动并读取一个 xml 文件,其中包含图像的 url。我已将 url 保留在与 swf 相同的文件夹中
是否可以根据其 website 上提供的规范开发 AUTOSAR BSW 堆栈(例如用于 CAN 通信)?不购买任何昂贵的供应商工具?可以遵循哪些步骤?我被要求探索这种可能性。 最佳答案 是和否。工具
有人知道如何用音频文件的内容覆盖 iPhone 麦克风吗? 想象一个场景,您正在通话,并且想要播放一些简短的音频让其他人听到。 因此,有必要将麦克风(硬件)置于保持状态,并使用委托(delegate)
我遇到了这个问题,我的应用程序出现 EXC_BAD_ACCESS 错误并卡住/停止。我使用模拟器的“向左旋转”和“向右旋转”选项来模拟方向变化行为。导致此错误的可能原因有哪些?由于我没有获得有关错误的
我有超过 1 台 Mac,我想在所有这些 Mac 上进行开发。我知道我需要在每台机器上同步我的手机,但这是我遇到的最小的问题。看起来我无法在手机上运行应用程序,除了在其中之一上开发的应用程序。 是否有
在手机上测试时,我的应用程序在特定点崩溃。控制台显示此消息 Tue Jan 27 15:47:14 unknown SpringBoard[22] : Application com.myprof.
我有一个案例,我从服务器获取信息。我的应用程序有一个选项卡栏和导航按钮。我希望应用程序显示进度指示器并禁用所有其他控件,以便用户在从服务器提取数据时无法跳转。我怎样才能实现这个目标? 我想到的一种方法
有时,当我尝试“构建”/编译下载的源代码时,我会收到以下警告: ld: warning: directory '/Volumes/Skiiing2/CD/ViewBased/Unknown Path/
我无法在 Apple 文档中找到关于开发和分发配置之间差异的明确解释。我目前正在使用开发配置在我的 iPhone 上进行开发和测试。我打算将该应用程序分发到我的 Beta 测试中,我想知道: 我需要使
我在使用 SharePoint 时遇到的最大挑战之一是它不能很好地适应典型的项目环境,其中至少包含开发和生产环境。我遇到的最多的问题是内容和列表是如此紧密地耦合在一起,以至于如果不在生产环境中执行内容
我失败了fist step让 Eclipse(对我来说是全新的)为 ARM 开发做好准备。 我在 Windows 10 中安装了 Eclipse。我想我应该安装 xpm,但我不知道在哪里输入此命令:
首先,我告诉你-我是编码新手 我正在使用vs代码来学习c++,它不会产生像dev c++或codeblocks这样的调试器。我看了一些视频,其中我们必须编辑json文件,这对于初学者来说非常复杂。有人
我失败了fist step让 Eclipse(对我来说是全新的)为 ARM 开发做好准备。 我在 Windows 10 中安装了 Eclipse。我想我应该安装 xpm,但我不知道在哪里输入此命令:
我开发了一个 Ionic 应用程序(iOS 和 Android 的混合)。我有 Xcode 8.3.3 并购买了一年的 Apple Developer Program 订阅。 我不想测试我的应用并将其
我是一名优秀的程序员,十分优秀!