




已阅读5页,还剩10页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
欢迎来到iPhone的世界 关于本书 必要条件 l 运行Leopard的基于Intel的Macintosh计算机l 注册成为iphone 开发人员,下载iphone SDK l 关于并标准版与企业版问题必备知识l Object-C编程知识l iPhone本身的熟悉(特性,界面,程序外观)Iphone程序有何不同l 只有一个正在运行的应用程序n 执行代码时唯一的运行程序l 只有一个窗口n 应用程序与用户所有交互在此完成l 受限访问n 程序访问权限(文件读写,网络端口访问,管理员操作)l 有限的响应时间n 较快的响应时间n 确保用户退出时不会丢失数据l 有限的屏幕大小n 480*320l 有限的系统资源n 内存不足,可用内存限制l 缺少Cocoa工具n 垃圾回收l 新属性l 与众不同的方法n 没有键盘鼠标的交互方式本书内容准备开始吧2创建基本项目在Xcode中设置项目启动Xcode创建新项目File-New Project iphone-application-项目模板View-Based Application Choose 保存 项目窗口Classes Obejct-C类Other Sources .pch main.mResources .xib .plist xibFramewWorks ProductsInterface Buider 简介Xib文件代码 UIButton *myButton=UIButton alloc initWithFrame:aRect;界面对象组件面板拖Nib文件的构成 视图中添加标签 双击添加文本 保存 Save Build Build and Run Inspector窗口Iphone 美化 .pngInfo.plist3处理基本交互模型-视图-控制器范型 MVCM 保存应用程序数据的类设计一些Object-C类来保存应用程序的数据V 窗口,控件和其他用户可以看到并能与之交互的元素组成部分C 将模型与视图绑定在一起,确定如何处理用户输入的应用程序逻辑开发人员创建的类和特定于应用程序的类组成 通用控制器类确保实现最大可重用性创建项目创建视图控制器UIViewController 子类输出口 IBOutlet UIButton *myButton;操作方法 (IBAction)doSomething:(id)sender;添加到接口#importinterface Button_FunViewController:UIViewControllerIBOutlet UILabel *statusText;property(retain,nonatomic) UILabel *statusText;-(IBAction) buttonPressed:(id)sender;end垃圾收集 如果定义的属性是一个对象,通常可选属性应该指定为 retain额外代码的生成开销 nonatomic点表示法 用于修改 访问添加到实现#import “Button_FunViewController.h”-implementation Button_FunViewControllersynthesize statusText;-(IBAction)buttonPressed:(id)senderNSString *title=sender titleForState:UIControlStateNormal;NSString *newText=NSString alloc initWithFormat:”% button pressed.”,title;statusText.text=newText;newText release;-(void)deallocstatusText release;super release;end简便方法 工厂方法如果未分配它或者保留它,则不要释放它。自动释放的代价 消息嵌套使用应用程序的委托Button_FunAppDelegate.h#importclass /注意 Button_FunViewController;interface Button_FunAppDelegate:NSObjectIBOutlet UIWindow *window;IBOutlet Button_FunViewController *viewController;property (nonatomic,retain) UIWindow *window;property (nonatomic,retain) Button_FunViewController *viewController;endButton_FunAppDelegate.m#import “Button_FunAppDelegate.h”#import”Button_FunViewController.h”implementation Button_FunAppDelegatesynthesize window;Synthesize viewController;-(void) applicationDidFinishLaunching:(UIApplication*)applicationwindow addSubview:viewController.view;window makeKeyAndVisible;-(void)deallocviewController release;window release;super dealloc;end编辑MainWindow.xib编辑Button_FunViewController.xibl Interface Builder中创建视图n 拖动l 连接所有元素n Control 单击 拖向 蓝色引导线 灰色菜单 statusTextn 指定操作l 测试4更丰富的用户界面满是控件的屏幕活动,静态和被动控件创建应用程序l 导入图像l 实现图像视图和文本字段a) 确定输出口b) 确定操作c) 构建界面l 添加图像视图a) 调整图像视图b) Mode属性 多大小显示为图创建多个副本c) Alpha滑块 除非有足够的理由,否则该值置为1.0d) 忽略background e) Tag属性 标记值 快速可靠确定sender参数传递给操作方法的控件f) Drawing复选框g) Interaction复选框l 添加文本字段a) 文本字段设置b) 文本输入特征c) 其他设置l 设置第二个文本字段的属性l 连接输出口构建运行完成输入后关闭键盘 -(IBAction)textFieldDoneEditing: (id)sendersender resignFirstResponder;通过触摸背景关闭键盘实现滑块和标签l 确定输出口和操作l 添加输出口和操作n IBOutlet UILabel *siderLabel;n proprerty (retain,nonatomic)UILabel *sliderLabel;n -(IBAction) sliderChanged: (id)sender;n n synthesize sliderLabel;n -(BAction)sliderChanged: (id)sendern u UISlider *slider=(UISlider*)sender;u Int progressAsInt=(int)(slider.value+0.5);u NSString *newText=NSString alloc initWithFormat:”%d”,progressAsInt;u sliderLabel.text=newText;u newText release;n l 添加滑块和标签l 连接操作和输出口实现开关和分段控件l 确定输出口和操作l 添加输出口和操作n #define kShowSegmentIndex 0n IBOutlet UISwitch *leftSwitch;n IBOutlet UISwitch *rightSwitch;n IBOutlet UIView *switchView;n n property (nonatomic,retain)UISwitch *leftSwitch;n property (nonatomic,retain)UISwitch *rightSwitch;n property (nonatomic,retain)UIView *switchView;n -(IBAction)switchChanged: (id)sender;n -(IBAction)toggleShowHide: (id)sender;n n synthesize leftSwitch;n synthesize rightSwitch;n synthesize switchView;n n -(IBAction)switchChanged: (id)sendern u UISwitch *whichSwitch = (UISwitch*)sender;u BOOL setting =whichSwitch.isOn;u leftSwitch setOn:setting animated:YES;u rightSwitch setOn:setting animated:YES;n n n -(IBAction)toggleShowHide: (id)sendern u UISegmentedControl *segmentedControl = (UISegmentedControl* ) sender;u NSInteger segment=segmentedControl.selectedSegmentIndex;u u If(segment = kShowSegmentedIndex)switchView setHidden:NO;u Else switchView setHidden:YES;n l 添加开关和分段控件n 添加另一个视图n 添加两个带标签的开关l 连接输出口实现按钮,操作表和警报l 添加输出口和操作n interface Control_FunViewController:UIViewControllerl n n IBOutlet UIButton *doSomethingButton;n n property (nontomic,retain)UIButton *dSmethingButton;n -(IBAction)doSomething: (id)sender;nl 在Interface Builder中添加按钮l 实现按钮的操作方法n synthesize doSomethingButton;n n -(IBAction)doSomething: (id)sendern u UIActionSheet *actionSheet = UIActionSheet alloc initWithTitle:”Are you sure ?” delegate:self cancelButtonTitle:”No Way!” destructiveButtonTitle:”Yes,I m sure!” otherBttonTitles:nil;u actionSheet showInView:self.view;u actionSheet release;n n -(void)actionSheet: (UIActionSheet*)actionSheetn didDismissWithButtonIndex: (NSInteger)bttonIndexn u If(!buttonIndex=actionSheet cancelButtonIndex)u l NSString *msg=nil;l If(nameField.text.length0)n Msg=NSString alloc initWithFormat: ”You can breathe easy,%,everything went OK.”,nameField.text;l Elsel Msg=”You can breathe easy,everything went OK.”; l l UIAlerView *alert= UIAlerView alloc initWithTitle: ”Something wasdone” message:msg delegate:self cancelButtonTitle:”Phew!” otherButtonTitles:nil;l alert show;l alert release;l msg release;lu n 显示操作表美化按钮l ViewDidLoad方法n -(void)viewDidLoadn u jmUIImage *buttonImageNormal=UIImage imageNamed: “whiteButton.png”;u UIImge *stretchableButtonImageNormal = buttonImageNormal strechableImageWithLeftCapWidth:12 topCapHeight:0;u doSomethingButton setBackgroundImage:stetchableButtonImageNormal forState:UIControlStateNormal;u UIImage *buttonImagePressed = UIImage imageNamed: ”blueButton.png” ;u UIImage *stetchableButtonImagePressed = buttonImagePressed stretchableImageWithLeftCapWidth:12 tpCapHeight:0;u doSomethingButton setBackgroundImage:stretchableButtonImagePressed forState:UIControlStateHeighted;u n l 控件状态n 普通n 突出显示n 禁用n 选中l 可拉伸的图像5自动旋转和自动调整大小使用自动调整属性处理旋转l 指定旋转支持 n Classes AutoSizeViewController.m n -(BOOL)shuldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientationn u Return (interfaceOrientation = UIInterfaceOrientationPortrait / | / YES);n nl 设计界面l 自动调整属性l 按钮的自动调整属性在旋转时重构视图l 声明和连接输出口l 在旋转式移动按钮n -(void)willAnimalSecondHalfOfRotationFromInterfaceOrientation:n (UIInterfaceOrientation)fromInterfaceOrientationn Durarion: (NSTimeInterval)durationn u UIInterfaceeOrientation toOrientation=erfaceOrientation;/UIView beginAnimations: ”move buttons” context:nil ;u If(toOrientation = UIInterfaceOrientationPortrait | toOrientation = UIInterfaceOrientationPorraitUpsideDown )u l Button1.frame = CGRectMake(20,20,125,125);u u Else l n Button1.frame =CGRectMake(20,20,125,125);l /UIView commitAnimations;n n n切换视图确定输出口和动作设计两个视图实现交换和动作链接Core Graphics框架6多视图应用程序l View Switcher 应用程序l 多视图应用程序的体系结构n 多视图控制器也是视图控制器n 内容试图剖析l 构建View Switchern 创建视图控制器和nib文件u Window-Base application n 修改应用程序委托n SwitchViewController.hn 修改MainWindow.xibn 编写SwitchViewController.mn 实现内容视图l 制作转换动画l 重构7标签栏与选取器Pickers应用程序委托与数据源建立工具栏框架创建文件设置内容视图nib添加根视图控制器IPHONE入门Initializing the MoveMe ApplicationMain l 创建应用程序的top-level autorelease pool 回收内存l 调用UIApplicationMain函数 来创建MoveMe应用的主要对象,初始化这些对象,并开始event-processing循环l 只有当该循环结束时应用程序从该程序返回Creating the Application Delegatel Delegate对象的创建和将应用程序窗口展示给用户l Delegate对象在应用退出时顺序的执行应用的shutdowm操作并保存所有下次启动时需要的状态信息l Nib文件用于连接应用程序对象和创建的delegate对象Create the Application Windowl 唯一运行的程序,只有一个窗口l 窗口负责用户界面的表面描画,视图对象提供实际的内容l 应用程序启动并准备开始处理事件时UIApplication 对象发送给delegate对象applicationDidFinishLaunching消息,提示delegate将内容放进窗口并且执行其他需要的初始化工作n 创建视图控制器实例来管理窗口内容视图n 使用需要进行内容管理的nib文件的名字初始化视图控制器n 添加控制器的视图作为窗口的子视图n 显示窗口n -(void)applicationDidFinishLanching: (UIApplication*)applicationn u UIViewController* aViewController=UIViewController alloc initWithNibName:”MoveMeView” bundle: NBundle mainBundle;u self.viewController=aViewController;u aViewController release;u UIView* controllersView=viewController view;u window addSubview:controllersView;u window makeKeyAndVisible;n n 早期别包含太多的任务,尤其是后期容易执行的任务,展示给用户时反应迟钝Drawing the welcome Buttonl 描画背景图片l 计算WELCOME字符串的坐标用来设置字符串的居中l 设置描画颜色为黑色
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 建筑亮化拍摄方案设计
- 单轨吊司机上岗考核试卷及答案
- 沈阳建筑桩基检测方案设计
- 2025版司法局《民事起诉状(姓名权、肖像权纠纷)》民事类法律文书(空白模板)
- 面食餐厅人才发展策略分析
- 银矿开采效率提升策略报告
- 成套的管理咨询方案
- 建筑方案设计时间进度
- 联合教堂建筑分析方案设计
- 班组开年趣味活动方案策划
- 黄冈市2025年高三年级9月调研考试(一模)生物试卷(含答案)
- 人工搬运培训课件
- 2025年哈尔滨投资集团有限责任公司校园招聘笔试备考题库含答案详解(精练)
- 城乡垃圾压缩站建设施工组织设计方案
- 安徽省合肥市六校联考2025-2026年高三上学期开学考试语文试卷(含答案)
- 2025债权收购委托代理合同
- 框架合作协议书合同模板
- 2025年辅警招聘考试试题库(附答案)(满分必刷)
- 热处理安全培训考试试题及答案解析
- 2025年北京市中考英语真题卷含答案解析
- 制鞋工岗前考核试卷及答案
评论
0/150
提交评论