zoukankan      html  css  js  c++  java
  • UIKit 之UIViewController & UIView

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


      UIViewController

      1、UIViewController主要有两种,一种是内容ViewController,用于展示内容.一种是容器ViewContrller,作为其它ViewContronller的容器,如UINavigationViewContrller.UIViewController主要作为data与view间的桥梁:
    另大部分通过delegate或target-action的事件处理也由UIViewController处理的
      2、 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。
      3、 苹果建议们在自定义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就是一种常用的方式。 
     
      4、对于要启动时要恢复应用之前的UI状态,可参考文档Preserving and Restoring State章节。
      5、用swift写一个Demo 熟悉语法外也试了一下各种present组合在iphone展现是如何的,popover应该要怎么做,自定义present动画已经了解但没加在demo里

      UIView
      1、 当UIView视图首次出现在屏幕上时,系统就会叫它画它的内容,然后截图作为这个视图可视化地引用,如果视图一直没有改变,载图会一直作为视图的内容被系统重用,直到视图内容改变,系统会对视图重新载图。当视图内容改变时,我们可以调用setNeedDisplay或detNeedDisplayInRect:重绘视图区域。视图的重绘是在下一runloop,所以可把很多改变组合在一起在下一个runloop一起执行。
      2、在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.

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

     (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。
  • 相关阅读:
    vue学习 基本简介,安装,示例,options
    python操作谷歌翻译
    Celery笔记
    nps内网穿透笔记
    初学django基础05 路由系统,django的请求与返回
    初学Django基础04 http|jsonresponse,filter模板过滤器,cvb与fvb
    计数二进制字符串
    字符串相加
    类与对象
    Arrays
  • 原文地址:https://www.cnblogs.com/chenxianming/p/5740525.html
Copyright © 2011-2022 走看看