UIKit 之UIViewController & UIView

   隔了好一段时间没写什么,这篇其实也不算一篇文章,只是一个知识要点的记录,好记性很差烂笔头,把看过了解到的东西记下来。html


  UIViewControllerios

  一、UIViewController主要有两种,一种是内容ViewController,用于展现内容.一种是容器ViewContrller,做为其它ViewContronller的容器,如UINavigationViewContrller.UIViewController主要做为data与view间的桥梁:
另大部分经过delegate或target-action的事件处理也由UIViewController处理的
  二、 When you present a view controller, UIKit looks for a view controller that provides a suitable context for the presentation. In many cases, UIKit chooses the nearest container view controller but it might also choose the window’s root view controller.大部分状况下,选择离当前view controller最近的(即最顶层的)容器UIViewController做为presentViewController,以下图
拿的是NavigationController做为presentViewController。
  三、 苹果建议们在自定义view controller能够先看下系统是否已经有对应知足需求的controller了,由于苹果已经实现了不少不一样功能的view controller。最后自定义view controller 也必定要遵循系统规则。
In cases where two view controllers need to communicate or pass data back and forth, they should always do so using explicitly defined public interfaces.
The delegation design pattern is frequently used to manage communication between view controllers.
controller之间传递数据必定要有明确的接口,delegate就是一种经常使用的方式。 
 
  四、对于要启动时要恢复应用以前的UI状态,可参考文档 Preserving and Restoring State章节。
  五、用swift写一个 Demo 熟悉语法外也试了一下各类present组合在iphone展示是如何的,popover应该要怎么作,自定义present动画已经了解但没加在demo里

   UIView
  一、 当UIView视图首次出如今屏幕上时,系统就会叫它画它的内容,而后截图做为这个视图可视化地引用,若是视图一直没有改变,载图会一直做为视图的内容被系统重用,直到视图内容改变,系统会对视图从新载图。当视图内容改变时,咱们能够调用setNeedDisplay或detNeedDisplayInRect:重绘视图区域。视图的重绘是在下一runloop,因此可把不少改变组合在一块儿在下一个runloop一块儿执行。
  二、在UIView中能够动画的属性包括:

  frame—Use this to animate position and size changes for the view.
  bounds—Use this to animate changes to the size of the view.
  center—Use this to animate the position of the view.
  transform—Use this to rotate or scale the view.
  alpha—Use this to change the transparency of the view.
  backgroundColor—Use this to change the background color of the view.
  contentStretch—Use this to change how the view’s contents stretch.  
要获得更多的控制的话能够layer及别中使用CoreAnimation.git

  三、有效使用UIViews一些要注意的地方github

 (1)并非全部的View都有对应的view controller
 (2)尽可能少用自定义绘制,除非系统如今支持不了你要的展示 
 (3)尽量为view的opaque设置为YES
   (4)不要在系统控件(如button中加入label或imageView以显示图片和文字)中嵌入subviews
   (5)若是window的rootView是容器类型的view controller的view,不须要咱们初始化view的size,它会根据状态栏的变化自动调整。
 (6)当你改变transform属性时,相对的都是UIView的中center自己
 (7)当transform属性不是identity,当前view的frame是不肯定的,应该要被忽略,而应该使用bounds和center。可是当前view的subviews的frame是能够,由于它们是相对于父view的bounds的。
   (8) 动画相关,做用于UIView相关的属性的代码至关于做用于它的layer.可是若是是自定义建立出来的layer,UIView类方法那些动画函数对它是不起做用的,那些动画block中参数对于它是无效的,这种状况应该要使用Core Animation。
相关文章
相关标签/搜索