一点笔记 about layout 兼purelayout + 需要自动布局对scrollView影响

文档地址

https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/AutolayoutPG/

1This constraint-based approach to design allows you to build user interfaces that dynamically respond to both internal and external changes. 

这个基于目标的约束设计用来允许你建立交互关系,这些交互关系动态的反应内在的和外在的改变。

2、external changes of occur when the size or shape of your superview changes.

当你的父视图的形状或者尺寸改变,外部的改变就发生了。

3、when your app’s content changes ,the new content may require a different layout than the old.

当你的app的内容改变的时候,新的内容也许需要一个相对老的不同的布局。

4、Auto Layout dynamically calculates the size and position of all the views in your view hierarchy

自动布局动态在你的视图层级计算所有视图的尺寸和位置。

5、a news app needs to adjust its layout based on the size of the individual news articles.

一个新闻app需要使用它的布局适应个体新闻的标题。

参老文章

 

 

http://www.jianshu.com/p/b637d3d21606

1、translatesAutoresizingMaskIntoConstraints

translate 转化,翻译

mask 布局

2、autoresizing 早期进行UI布局的技术,仅使用于约束父子控件之间的关系

3、autoLayout 比autoresizing 更高级,旨在替代autoresizing,可以设置任何控件之间的关系。

4、sizeclass用于解决越来越多的屏幕尺寸的适配问题。

5、autoresizing 和auto layout 不能共存,所以如果使用autoresizing ,就不能勾选use auto layout.

6、每在storyboard 中对控件添加一个约束,就代表添加了一个约束对象。

7、leading edges 走边对齐

     trailing edges右边对齐

    top edges 顶部对齐

    bottom edges 底部对齐

8、By default, the autoresizing mask on a view gives rise to constraints that fully determine 

 the view's position. This allows the auto layout system to track the frames of views whose 

 layout is controlled manually (through -setFrame:, for example).

 When you elect to position the view using auto layout by adding your own constraints, 

 you must set this property to NO. IB will do this for you.

gives rise to  产生了

默认情况下,在视图自动布局产生了决定视图位置的约束,这允许自动布局系统去追踪那些通过人为控制的视图的frame,当你选择通过自动布局来设定你自己的位置的时候,你必须将这个属性设置为no,ib将会替你做这个事。

9、By default, the property is set totrue for any view you programmatically create. If you add views in Interface Builder, the system automatically sets this property tofalse.

默认情况下,当你书写代码时,这个属性被设置为yes,但当你给ib加视图时,系统会自动设置这个属性为false.

pure layout 

 

1、在 UITextView+PlaceHolder里面,

为什么只能用[view autoPinEdge:ALEdgeRight toEdge:ALEdgeRight ofView:[self superview] withOffset:-30];

不能用 [view autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:- (2 * DISTANCEY)];

2、友盟分享崩溃,点击那个tap栏,挂掉了。————商量

3、加载图片时,记得不要去加载那些框架里面的,那些图片加载不到。我们去调用iamge@2x.png调用不到。

4、edge top,bottom,left,right 是正数,那么他都在superview的里面

5、That is, if you pin a view to the left edge of its superview, you’re really pinning it to the minimum x-value of the superview’s bounds. Changing the bounds origin of the superview does not change the position of the view.

那是,如果你给一个视图设置了一个边沿的约束,你是真的设置了这个视图对你的父视图的最大的x值,改变父视图的位置不会改变这个视图的位置。

5、The UIScrollView class scrolls its content by changing the origin of its bounds. To make this work with Auto Layout, the top, left, bottom, and right edges within a scroll view now mean the edges of its content view.

滑动视图通过改变它的origin来滑动它的视图,为了让滑动视图适应自动布局,在一个滑动视图的顶、左、底、右边沿意味着这是他的内容视图的边沿。

6、Mixed Approach混合方法

7、Position and size your scroll view with constraints external to the scroll view—that is, the translatesAutoresizingMaskIntoConstraints property is set to NO.

你用约束滑动视图的位置和尺寸与scrollview不相关,换句话说,translatesAutoresizingMaskIntoConstraints属性设置为NO

8、Create a plain UIView content view for your scroll view that will be the size you want your content to have. Make it a subview of the scroll view but let it continue to translate the autoresizing mask into constraints。

为你的滑动视图创建一个清晰地视图,这个内容视图将会是你的滑动视图需要的尺寸。使它成为你滑动视图的子视图,但是让它继续将 the autoresizing mask转换为约束。

9、Create the views you want to put inside the content view and configure their constraints so as to position them within the content view.

创建你想放到内容视图的视图集,配置他们的约束在内容视图的里面。

10、[self.shareLabel autoAlignAxisToSuperviewMarginAxis:ALAxisVertical];设置水平居中

 

第二次学习:

滑动视图的原理

1、利用视图层次结构观察滚动后的 scrollView 和 imageView 的 position(center) 和 bounds 的变化

2、对比滑动前后的数据,只有ScrollView的bounds中的x发生了改变

3、滚动过程中 scrollView 本身的 frame 并没有发生变化

4、滚动过程中 imageView 本身的 frame 也没有发生变化

5、滚动过程中 scrollView 的 bounds 的 (x, y) 发生了变化

6、so.经过多次的验证,滑动只会改变ScrollView的bounds 

既通过改变ScrollView自身的原点来改变子控件的位置 

注:bounds我们通常用于修改大小,如果修改了x,y对自身不会发生什么影响 

只会影响子物体所参照的父对象原点,默认原点是自身的左上角,修改bounds的x,y后自身原点会发生位移,x,y都大于0的时候,向左上角方向移动,与frame恰好相反

7、UIScrollViewIndicatorStyle 这个属性设置滑动条风格

8、directionalLockEnabled

设置是否锁定,这个属性很有意思,默认为NO,当设置为YES时,你的滚动视图只能同一时间在一个方向上滚动,但是当你从对角线拖动时,是时刻在水平和竖直方向同时滚动的。

9、decelerationRate设置滑动速度

10、因为滑动视图的基本原理是改变bound值,所有有时设置约束值无效,要特殊照顾,但回答登录处为什么能做到,要好好想想。

11、contentsize可以理解为bound的滑动范围

滑动视图的约束

出处

https://blog.csdn.net/qq_29892943/article/details/77094917

1、scrollView自身的约束(scrollView的位置和尺寸)可以像正常的UIView一样参照器父控件添加,四个约束决定了scrollView的大小和位置,这步是没有问题的。

2、问题的关键在于如何给scrollView内部的子控件添加约束

3、scrollView的内部控件约束的添加需要遵循两个原则

(1)scrollView的内部子控件的尺寸不能以scrollView的尺寸为参照

(2)scrollView内部的子控件的约束必须完整

4、子控件的尺寸不能以scrollView的尺寸为参照,那么我们有两种选择

(1)提供一个具体指的约束

(2)子控件的尺寸可以参照scrollView以外其他的控件的尺寸(如控制器的view的尺寸)

5、其次约束“完整”的意思是说,子控件在水平及竖直方向上的约束要把scrollView撑满,也就是说,

在水平方向上,我们需要设置

(1)子控件左侧与父控件的距离

(2)子控件自身的宽度

(3)子控件右侧距父控件的距离

竖直方向上也一样,要设置

(1)子控件顶部距父控件的距离

(2)子控件的高度

(3)子控件底部距父控件的距离

 

出处

https://www.jianshu.com/p/c7937d844d85

1、scrollView的contentSize要根据containerView的高度来设置,containView的高度又要根据它内部的子控件来设置,make.bottom.equalTo(self.containerView)确定containerView的高度,make.width.equalTo(self.scrollView)确定containerview的宽度。

这段话的意思,其实就是上面第五点说的意思,为什么第五点要进行这么繁重的设置呢,就是用来确定contentSize的高度

down is new

2、给滑动视图增加一个子视图,是确定滑动视图的高度,至于确定了高度后,滑动视图上面的子视图加不加到contrainer视图上,就不一定了,加不加无所谓。

加到containView上可以,加到self.view也行。

第三次学习:

- (void)setNeedsLayout;

- (void)layoutIfNeeded;

- (void)layoutSubviews;    // 

等这几个函数好好理解

顺便研究messageCell的约束

作者:LYPC_下里巴人

链接:https://www.jianshu.com/p/2ef48c2f0c97

来源:简书

简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

这个方法,默认没有做任何事情,需要子类进行重写 。 系统在很多时候会去调用这个方法,初始化不会触发layoutSubviews,但是如果设置了不为CGRectZero的frame的时候就会触发。

(一)layoutSubviews

1.直接调用[self setNeedsLayout];(这个在上面苹果官方文档里有说明)
2.addSubview的时候。
3.当view的size发生改变的时候,前提是frame的值设置前后发生了变化。
4.滑动UIScrollView的时候。
5.旋转Screen会触发父UIView上的layoutSubviews事件(这个我验证了一下 确实没有触发layoutSubviews方法,查了很多资料都说会触发,大家自己定夺)。

(2)layoutifNeeded

也就是使用约束的时候,掉一下可以立即更新效果

setNeedsLayout方法并不会理解刷新,立即刷新需要调用layoutifNeeded方法

(3)setNeedsDisplay

与setNeedsLayout方法相似的方法是setNeedsDisplay方法。该方法在调用时,会自动调用drawRect方法。drawRect方法主要用来画图。所以,当需要刷新布局时,用setNeedsLayOut方法。drawRect方法主要用来画图。所以,当需要刷新布局时,用setNeedsLayout方法:当需要重新绘制时,调用setNeedsDisplay方法

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值