AutoLayout(转)
转自 http://blog.sina.com.cn/s/blog_9564cb6e0101wv9o.html
controller和View的责任分配:
1、View指定固有的content size
leaf-level views,比如buttons相比分配位置的代码,它自己更应该知道它自己size是多大。intrinsicContentSize,告诉layout system在一个视图内有一些内容它并不了解;这个方法在子类中被重写,被layout system调用。一个View可返回它的宽高或者NSViewNoInstrinsicMetric
2、Controller 指定intrinsic多重要
尽管一个View指定了它的固定content size,这个View的使用者会说intrinsic多重要.setContentHuggingPriority:forOrientation: setContentCompressionResystancePriority:forOrientation:
3、如果实现了一个自定义View:1)updateConstraints 2)layout
setTranslatesAutoresizingMaskIntoConstraints: view的autoresing Mask是否需要被翻译成constriants.因为通常情况下view的autoresing mask产生的constraints完全指定了view的位置,如果想要constraints更加灵活,必须忽略autoresingMask,既NO。IB创建的视图已经设置为NO。
Visual Format Language
1、standard space: [button]-[textField]
2、width constraint :[button(>=50)]
3、Connection to superView : |-50-[orchbox]-50-|
4、Vertical Layout: V:[topField]-10-[bottomField]
5、Flush Views:[maroonView][oceanView]
6、Priority:[button(100@20)]
7、Equal Width: [button1(==button2)]
8、Multple predicates: [flexibleButton(>=70,<=90)]
NSLayoutFormatOptions
NSLayoutFormatAlignAllLeft = NSLayoutAttributeLeft 对象的标准矩形区域左侧
NSLayoutFormatAlignAllRight = NSLayoutAttributeRight 对象的标准矩形区域右侧
NSLayoutFormatAlignAllTop = NSLayoutAttributeTop 对象的标准矩形区域上侧
NSLayoutFormatAlignAllBottom = NSLayoutAttributeBottom 对象的标准矩形区域下侧
NSLayoutFormatAlignAllLeading = NSLayoutAttributeLeading 对象的标准矩形区域前沿
NSLayoutFormatAlignAllTrailing = NSLayoutAttributeTrailing 对象的标准矩形区域末尾
NSLayoutFormatAlignAllCenterX = NSLayoutAttributeCenterX 对象的标准矩形区域x轴中点
NSLayoutFormatAlignAllCenterY = NSLayoutAttributeCenterY 对象的标准矩形区域y轴中点
NSLayoutFormatAlignAllBaseLine = NSLayoutAttributeBaseLine 对象的baseline
setContentHuggingPriority:forOrientation: 在指定方向上,view反对超过它的固定大小,NSLayoutPriorityDefaultLow,NSLayoutPriorityDefaultHight
setContentCompressionResistancePrioriry:Orientation: 在指定方向上,view小于它的固定大小的抵抗优先级
NSLayoutPriority :
NSLayoutPriorityRequired 1000 ;
NSLayoutPriorityDefaultHigh 750 button不压缩它的内容;
NSLayoutPriorityDragThatCanResizeWindow 510;
NSLayoutPriotiryWindowSizeStayPut 500 窗口大小保持不变,实际上你希望比它大或小;
NSLayoutPriorityDragCannotResizeWindow 490 splite view拆分,拖动不改变窗口大小;
NSLayoutPriorityDefaultLow 250 一个button水平包含它的内容;
NSLayoutPriorityFittingSizeCompression 50;
requiresConstraintBasedLayout 自定义view应该重写这个方法返回YES,如果它不能使用autoresing正确的布局
AutoLayout(转)的更多相关文章
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
本文翻译自:stackoverflow 有人在stackoverflow上问了一个问题: 1 如何在UITableViewCell中使用Autolayout来实现Cell的内容和子视图自动计算行高,并 ...
- Masonry介绍与使用实践:快速上手Autolayout
1 MagicNumber -> autoresizingMask -> autolayout 以上是纯手写代码所经历的关于页面布局的三个时期 在iphone1-iphone3gs时代 w ...
- 利用代码添加autolayout约束
1.概述 通常我们通过storyboard能够完成的,代码也能够完成,所以这里介绍下代码实现约束的添加,通常我们不这么干(在不使用第三方框架的情况下,使用系统自带的类添加约束特别繁琐),所以这里仅仅简 ...
- 【原】iOS学习之苹果原生代码实现Autolayout和VFL语言
1.添加约束的规则 在创建约束之后,需要将其添加到作用的view上 在添加时要注意目标view需要遵循以下规则: 1)对于 两个同层级view之间 的约束关系,添加到它们的父view上 2)对于 两个 ...
- iOS学习笔记——AutoLayout的约束
iOS学习笔记——AutoLayout约束 之前在开发iOS app时一直以为苹果的布局是绝对布局,在IB中拖拉控件运行或者直接使用代码去调整控件都会发上一些不尽人意的结果,后来发现iOS在引入了Au ...
- iOS AutoLayout的用法
添加约束 代码实现Autolayout的步骤 利用NSLayoutConstraint类创建具体的约束对象 添加约束对象到相应的view上 - (void)addConstraint:(NSLayou ...
- AutoLayout(自动布局)
1. iOS两种自适应布局方式:(修正说明:) -AutoLayout(自动布局) + SizeClasses(尺寸类别) -Autoresizing (自动调整尺寸/弹簧式调整尺寸) 前者 Auto ...
- iOS-自动布局Autolayout(原创)
前言 基础知识 在一定情况下我们需要用到自动布局(autolayout) 这样我们就能使视图与视图之间的位置相互关联起来 横向:距离父视图左侧100 视图本身的宽度最小是100 距离父视图右侧是100 ...
- iOS - XIB之AutoLayout添加约束
XIB--AutoLayout添加约束 仿QQ登录界面: 说明:以下各图背景红色只是方便看清楚: 1.创建工程:创建xib文件 2.打开xib文件: (1).创建头像: 拖控件:uiimageview ...
- iOS AutoLayout自动布局&Masonry介绍与使用实践
Masonry介绍与使用实践:快速上手Autolayout http://www.cnblogs.com/xiaofeixiang/p/5127825.html http://www.cocoachi ...
随机推荐
- codeforces C. Inna and Huge Candy Matrix
http://codeforces.com/problemset/problem/400/C 题意:给你一个n*m的矩阵,然后在矩阵中有p个糖果,给你每个糖果的初始位置,然后经过x次顺时针反转,y次旋 ...
- 获得进程可执行文件的路径: GetModuleFileNameEx, GetProcessImageFileName, QueryFullProcessImageName
http://blog.csdn.net/bichenggui/article/details/4774457 -------------------------------------------- ...
- C# DataGridView 导出 Excel(根据Excel版本显示选择不同后缀格式xls或xlsx)
/// <summary> /// DataGridView导出至Excel,解决问题:打开Excel文件格式与扩展名指定格式不一致 /// </summary> /// &l ...
- 设置Git提交时不用输入用户名和密码
在用git提交时代码至github上时每次都要输入用户名和密码,当提交操作较为频繁时非常不方便,可以按下文中的介绍,设置成提交时不用输入用户名和密码: 1.在当前库下,已经运行过 git remote ...
- POJ 3694 Network(无向图求桥+重边处理+LCA)
题目大意: 给你一个无向图,然后再给你一个Q代表有Q次询问,每一次加一条边之后还有几座桥.在这里要对重边进行处理. 每次加入一条边之后,在这条搜索树上两个点的公共祖先都上所有点的桥都没了. 这里重边的 ...
- 树(最小乘积生成树,克鲁斯卡尔算法):BOI timeismoney
The NetLine company wants to offer broadband internet to N towns. For this, it suffices to construct ...
- 图论(网络流):SPOJ OPTM - Optimal Marks
OPTM - Optimal Marks You are given an undirected graph G(V, E). Each vertex has a mark which is an i ...
- 动态规划(状态压缩):BZOJ 2621 [Usaco2012 Mar]Cows in a Skyscraper
2621: [Usaco2012 Mar]Cows in a Skyscraper Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 303 Sol ...
- 数据结构(主席树):HDU 5654 xiaoxin and his watermelon candy
Problem Description During his six grade summer vacation, xiaoxin got lots of watermelon candies fro ...
- 网络流(最大流):POJ 1149 PIGS
PIGS Time Limit: 1000ms Memory Limit: 10000KB This problem will be judged on PKU. 64-bit integer(整数) ...