添加递进式子视图实例学习

【基础】
iPhone编程中心采用两种重要的范型:
面向对象范型
模型-视图-控制器(MVC)设计模式

iPhone上的MVC划分:
视图        由UIView类以及子类以及其相关的UIViewController类提供。PS:关于此处Controller,个人认知为一个容器,用于保存UIView类的实例,同时负责对屏幕中各项进行布局。

控制器        通过3中关键技术实现:委托、目标操作和通知
模型        模型方法拖过数据源和数据含义等协议提供数据,需要实现由控制器触发的回调方法。

【实例学习】
在实践Pdf版书中P47的例子中,通过苹果官网资料学习:

UIView类

常用属性:
    superview
    subviews
    window
    autoresizingMask UIViewAutoresizing常量,常用UIViewAutoresizingFlexibleWidth and UIViewAutoresizingFlexibleRightMargin
    autoresizesSubviews    标记子视图是否自动重设大小
    tag    标识视图的标签

常用方法:
    addSubview
    insertSubview
    removeFromSuperview
    viewWithTag    通过标识获取视图指针

UIViewController类

为苹果应用程序提供基本的view-management(视图管理)模型。
UINavigationController,UITabBarController是此类的子类,提供额外行为操作来管理复杂层次关系视图控制器和视图。

常用属性:
view:
    当前控制器管理的视图,为控制器当前可见的视图


常用方法:
loadView:
    创建视图用于控制器使用。

willRotateToInterfaceOrientation:
    用于屏幕翻转告知控制器,以响应对应的改变

shouldAutorotateToInterfaceOrientation:
    返回一个Bool值,来指示当前视图控制器是否支持指定的方向   
    此函数涉及一个常量,如下:
        UIInterfaceOrientation常量:

        typedef enum {
           UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,
           UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,
           UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,
           UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft
        } UIInterfaceOrientation;
   
    用于判断用户的屏幕横放和竖放是否支持。比如:看视频,一般都是横起看,那么取值只能UIDeviceOrientationLandscapeRight或UIDeviceOrientationLandscapeLeft。完整代码如下:
    // Allow the view to respond to 2 iPhone Orientation changes,like:
    -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation == UIDeviceOrientationLandscapeRight || interfaceOrientation == UIDeviceOrientationLandscapeLeft);
    }
   
几何类型结构:
CGRect

    A structure that contains the location and dimensions of a rectangle.

    struct CGRect {
       CGPoint origin;
       CGSize size;
    };
    typedef struct CGRect CGRect;

CGPoint

    A structure that contains a point in a two-dimensional coordinate system.

    struct CGPoint {
       CGFloat x;
       CGFloat y;
    };
    typedef struct CGPoint CGPoint;

CGSize

    A structure that contains width and height values.

    struct CGSize {
       CGFloat width;
       CGFloat height;
    };
    typedef struct CGSize CGSize;

CGFloat

    The basic type for all floating-point values.

    typedef float CGFloat;// 32-bit

    typedef double CGFloat;// 64-bit



无论生活、还是技术,一切都不断的学习和更新~~~努力~
原文地址:https://www.cnblogs.com/GoGoagg/p/2049072.html