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

移动开发 iOS
iPhone编程添加递进式子视图实例学习是本文要介绍的内容,主要是来系统的来学习iphone编程中的一些细节问题,来看本文内容详解。

iPhone编程添加递进式子视图实例学习是本文要介绍的内容,主要是来系统的来学习iphone编程中的一些细节和视图的相关问题,来看本文内容详解。iPhone编程中心采用两种重要的范型:

面向对象范型

模型-视图-控制器(MVC)设计模式

iPhone上的MVC划分:

视图       

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

控制器      
 
通过3中关键技术实现:委托、目标操作和通知

模型      
 
模型方法拖过数据源和数据含义等协议提供数据,需要实现由控制器触发的回调方法。

实例学习

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

UIView类

常用属性:

  1. superview  
  2. subviews  
  3. window  
  4. autoresizingMask UIViewAutoresizing常量,
  5. 常用UIViewAutoresizingFlexibleWidth and UIViewAutoresizingFlexibleRightMargin  
  6. autoresizesSubviews    标记子视图是否自动重设大小  
  7. tag    标识视图的标签 

常用方法:

  1. addSubview  
  2. insertSubview  
  3. removeFromSuperview  
  4. viewWithTag    通过标识获取视图指针 

UIViewController类

为苹果应用程序提供基本的view-management(视图管理)模型。

UINavigationController,UITabBarController是此类的子类,提供额外行为操作来管理复杂层次关系视图控制器和视图。

常用属性:

view:

当前控制器管理的视图,为控制器当前可见的视图

常用方法:

loadView:

创建视图用于控制器使用。

willRotateToInterfaceOrientation:

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

shouldAutorotateToInterfaceOrientation:

返回一个Bool值,来指示当前视图控制器是否支持指定的方向   

此函数涉及一个常量,如下:

UIInterfaceOrientation常量:

  1. typedef enum {  
  2.    UIInterfaceOrientationPortrait           = UIDeviceOrientationPortrait,  
  3.    UIInterfaceOrientationPortraitUpsideDown = UIDeviceOrientationPortraitUpsideDown,  
  4.    UIInterfaceOrientationLandscapeLeft      = UIDeviceOrientationLandscapeRight,  
  5.    UIInterfaceOrientationLandscapeRight     = UIDeviceOrientationLandscapeLeft 
  6. } UIInterfaceOrientation; 

用于判断用户的屏幕横放和竖放是否支持。比如:看视频,一般都是横起看,那么取值只能UIDeviceOrientationLandscapeRight UIDeviceOrientationLandscapeLeft。完整代码如下:

  1. // Allow the view to respond to 2 iPhone Orientation changes,like:  
  2. -(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
  3. {  
  4.     return (interfaceOrientation == UIDeviceOrientationLandscapeRight || interfaceOrientation == UIDeviceOrientationLandscapeLeft);  

几何类型结构:

CGRect

  1. A structure that contains the location and dimensions of a rectangle.  
  2.  
  3.     struct CGRect {  
  4.        CGPoint origin;  
  5.        CGSize size;  
  6.     };  
  7.     typedef struct CGRect CGRect; 

CGPoint

  1. A structure that contains a point in a two-dimensional coordinate system.  
  2.  
  3.     struct CGPoint {  
  4.        CGFloat x;  
  5.        CGFloat y;  
  6.     };  
  7.     typedef struct CGPoint CGPoint; 

CGSize

  1. A structure that contains width and height values.  
  2.  
  3.     struct CGSize {  
  4.        CGFloat width;  
  5.        CGFloat height;  
  6.     };  
  7.     typedef struct CGSize CGSize; 

CGFloat

  1. The basic type for all floating-point values.  
  2. typedef float CGFloat;// 32-bit  
  3. typedef double CGFloat;// 64-bit 

小结:iPhone编程添加递进式子视图实例学习的内容介绍完了,希望本文能对你有所帮助!

责任编辑:zhaolei 来源: 博客园
相关推荐

2011-07-22 17:24:46

iPhone 视图

2011-07-18 15:32:14

iPhone 录音 播放

2011-08-11 16:19:11

iPhoneCocoa

2011-08-15 18:02:32

iPhone开发表视图

2011-07-26 15:56:53

iPhone 游戏 启动画面

2011-08-08 15:56:18

iPhone 震动 NSUserDefa

2011-07-28 14:19:12

iPhone 网络编程 聊天程序

2021-04-30 18:50:44

网络安全PE编程添加节区

2011-07-21 17:29:42

iPhone Sqlite 数据库

2009-09-23 15:12:41

Hibernate视图

2011-08-12 11:23:47

iPhone窗口视图

2011-07-27 17:45:29

iPhone 模拟器 图片

2011-07-29 10:51:41

iPhone 全屏显示 视图

2011-07-25 18:02:51

iPhone LibFetion 移植

2009-08-28 17:51:40

iPhone多视图开发

2011-08-08 16:56:44

iPhone 字符处理 视图

2011-07-21 16:48:19

iPhone 游戏

2011-08-12 10:04:24

iPhone开发视图

2011-07-06 16:15:46

iPhone 图片

2011-07-18 13:37:53

点赞
收藏

51CTO技术栈公众号