iOS UIView
来源:互联网 发布:笔记本电脑散热器软件 编辑:程序博客网 时间:2024/05/16 19:53
iOS UIView
View Programming Guide for iOS
深入了解UIView,记录下View Programming Guide for iOS中相关内容。
UIView的事件响应顺序
When a touch occurs inside a specific view, the system sends an event object with the touch information directly to that view for handling. However, if the view does not handle a particular touch event, it can pass the event object along to its superview. If the superview does not handle the event, it passes the event object to its superview, and so on up the responder chain. Specific views can also pass the event object to an intervening responder object, such as a view controller. If no object handles the event, it eventually reaches the application object, which generally discards it.
Content Modes
Each view has a content mode that controls how the view recycles its content in response to changes in the view’s geometry(几何结构) and whether it recycles its content at all. When a view is first displayed, it renders its content as usual and the results are captured in an underlying(潜在的) bitmap. After that, changes to the view’s geometry do not always cause the bitmap to be recreated. Instead, the value in the contentMode
property determines whether the bitmap should be scaled to fit the new bounds or simply pinned to one corner or edge of the view.
如下的动作会导致content mode被应用:
- Change the width or height of the view’s
frame
orbounds
rectangles. - Assign a transform that includes a scaling factor to the view’s
transform
property.
默认的view的frame超出superview的部分是不会被裁剪的,把clipsToBounds
设为YES
可以达到裁剪的结果。裁剪之后,发生在view被裁剪区的触摸事件不会被deliver到view上。
setNeedsLayout
vs layoutIfNeeded
参考setNeedsLayout vs layoutIfNeeded Explained
system会标记需要redrawn的view,在update cycle中来redrawing
setNeedsLayout
告知system你想要layout并redraw所有的view及其子view,在update cycle的时候。这是一个异步的activity,你不知道update cycle什么时候会到来。
layoutIfNeeded
是一个同步的过程,告知system你想要立即layout和redraw这个view及其子view,需要立即做,不要等待update cycle。
所以layoutIfNeeded
会立即更新,而setNeedsLayout
等待至下一个update cycle
View运行时交互模型(The Runtime Interaction Model for Views)
- user触摸屏幕
- 硬件把touch event报告给UIKit
- UIKit把touch包装成一
UIEvent
对象,并把它分派到对应的view。 view的事件处理code来响应event。例如,你的代码可能如下:
- 改变view或者其subview的属性(frame, bounds, alpha等)
- 调用
setNeedsLayout
方法,把view(或者其subview)mark为需要更新布局 - 调用
setNeedsDisplay
或者setNeedsDisplayInRect:
方法,把view(或者其subview)mark为需要被重绘 - 通知controller改变部分数据
如果view的geometry有任何的改变,UIKit按照以下的规则来更新它的subviews:
a. 如果你配置了autoresizing,UIkit根据这些规则来调整每个view
b.如果view实现了layoutSubviews
方法,UIKit会调用这个方法如果view的一部分被mark为需要被redrawn,UIKit会要求view重绘它自身
- 更新后的view会与应用的其它可见的content合成,然后给硬件来显示
- 硬件把渲染后的内容显示在屏幕上
Windows
一个Window对象有如下的功能:
- It contains your application’s visible content.
- It plays a key role in the delivery of touch events to your views and other application objects.
- It works with your application’s view controllers to facilitate orientation changes.
- IOS-UIView
- IOS UIView
- IOS UIView
- iOS UIView
- IOS UIView
- iOS UIView
- iOS UIView
- iOS UIView
- ios uiView run animate
- iOS的UIView
- ios UIView详解~~~~~
- iOS UIview传递参数
- IOS 应用UIView分析
- UIView-IOS开发
- iOS学习--UIView详解~~~~~
- IOS控件UIToolBar、UIView
- ios UIView 动画效果
- ios UIView详解~~~~~
- Android 微信支付详解及总结
- 【技术支持】开发人员从客户数据库环境中导出数据用户测试的几种方法途径
- 判断android手机中有无某个程序
- iOS APP 如何做才安全
- 开发网络程序验证效率和稳定性时需要注意的几个问题
- iOS UIView
- 利用 Android Studio 和 Gradle 打包多版本APK
- fft模板
- 引用的释放管理
- 1.Basic Structure
- java mysql batchquery批量添加
- Provisional headers are shown 错误可能原因
- Test
- Dubbo初识