ios开发笔记.doc

上传人:hw****26 文档编号:3551535 上传时间:2019-06-04 格式:DOC 页数:54 大小:793.50KB
下载 相关 举报
ios开发笔记.doc_第1页
第1页 / 共54页
ios开发笔记.doc_第2页
第2页 / 共54页
ios开发笔记.doc_第3页
第3页 / 共54页
ios开发笔记.doc_第4页
第4页 / 共54页
ios开发笔记.doc_第5页
第5页 / 共54页
点击查看更多>>
资源描述

1、iphone 开发笔记退回输入键盘- (BOOL) textFieldShouldReturn:(id)textFieldtextField resignFirstResponder;CGRectCGRect frame = CGRectMake (origin.x, origin.y, size.width, size.height);矩形NSStringFromCGRect(someCG) 把 CGRect 结构转变为格式化字符串;CGRectFromString(aString) 由字符串恢复出矩形;CGRectInset(aRect) 创建较小或较大的矩形(中心点相同) ,较小 较大C

2、GRectIntersectsRect(rect1, rect2) 判断两矩形是否交叉,是否重叠CGRectZero 高度和宽度为零的位于(0,0)的矩形常量CGPoint CGSize aSize = CGSizeMake(width, height);设置透明度myView setAlpha:value; (0.0 - (IBActive) someButtonPressed:(id) senderUIActionSheet *actionSheet = UIActionSheet alloc initWithTitle:”Are you sure?”delegate:selfcancel

3、ButtonTitle:”No way!”destructiveButtonTitle:”Yes, Im Sure!”otherButtonTitles:nil;actionSheet showInView:self.view;actionSheet release;警告视图 - (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndexif(buttonIndex != actionSheet cancelButtonIndex)NSString *mess

4、age = NSString alloc initWithFormat:”You can breathe easy, everything went OK.”;UIAlertView *alert = UIAlertView alloc initWithTitle:”Something was done”message:messagedelegate:selfcancelButtonTitle:”OK”otherButtonTitles:nil;alert show;alert release;message release;动画效果-(void)doChange:(id)senderif(v

5、iew2 = nil)self loadSec;UIView beginAnimations:nil context:NULL;UIView setAnimationDuration:1; UIView setAnimationTransition:(view1 superview?UIViewAnimationTransitionFlipFromLeft:UIViewAnimationTransitionFlipFromRight)forView:self.view cache:YES;if(view1 superview!= nil)view1 removeFromSuperview;se

6、lf.view addSubview:view2;else view2 removeFromSuperview;self.view addSubview:view1;UIView commitAnimations;Table View #pragma mark -#pragma mark Table View Data Source Methods/指定分区中的行数,默认为 1- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionreturn self.listData c

7、ount;/设置每一行 cell 显示的内容- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPathstatic NSString *SimpleTableIndentifier = “SimpleTableIndentifier“;UITableViewCell *cell = tableView dequeueReusableCellWithIdentifier:SimpleTableIndentifier;if (cell = nil) ce

8、ll = UITableViewCell alloc initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:SimpleTableIndentifier autorelease;UIImage *image = UIImage imageNamed:“13.gif“;cell.imageView.image = image;NSUInteger row = indexPath row;cell.textLabel.text = listData objectAtIndex:row;cell.textLabel.font = UIF

9、ont boldSystemFontOfSize:20;if(row #pragma mark -#pragma mark Table View Delegate Methods/把每一行缩进级别设置为其行号- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPathNSUInteger row = indexPath row;return row;/获取传递过来的 indexPath 值- (NSIndexPath *)tableView:(

10、UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPathNSUInteger row = indexPath row;if (row = 0) return nil;return indexPath;- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPathNSUInteger row = indexPath row;NSString *rowValue = listData obj

11、ectAtIndex:row;NSString *message = NSString alloc initWithFormat:“You selected %“,rowValue;UIAlertView *alert = UIAlertView alloc initWithTitle:“Row Selected“message:messagedelegate:nilcancelButtonTitle:“Yes, I did!“otherButtonTitles:nil;alert show;alert release;message release;tableView deselectRow

12、AtIndexPath:indexPath animated:YES;/设置行的高度- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPathreturn 40;NavigationController 推出 push 推出 popself.navigationController pushViewController:_detailController animated:YES;self.navigationController popViewController

13、Animated:YES;Debug:NSLog(“%s %d“, _FUNCTION_, _LINE_);点击 textField 外的地方回收键盘先定义一个 UIControl 类型的对象,在上面可以添加触发事件,令 SEL 实践为回收键盘的方法,最后将 UIControl 的实例加到当前 View 上。UIControl *m_control = UIControl alloc initWithFrame:CGRectMake(0, 0, 320, 480);m_control addTarget:self action:selector(keyboardReturn) forContr

14、olEvents:UIControlEventTouchUpInside;self.view addSubview:m_control;- (void) keyboardReturnaTextField resignFirstResponder;键盘覆盖输入框当键盘调出时将输入框覆盖时,可以用下方法:- (BOOL)textFieldShouldBeginEditing:(UITextField *)textFieldself.view setFrame:CGRectMake(0, -100, 320, 480) ;return YES;- (BOOL)textFieldShouldEndEd

15、iting:(UITextField *)textFieldself.view setFrame:CGRectMake(0, 0, 320, 480);return YES;当准备输入时,将视图的位置上调 100,这样键盘就不能覆盖到输入框。当依赖注入方法不好使时,可以在 AppDelegate 内申明一个全局的控制器实例_anotherViewController,在另一个需要使用_anotherViewController 的地方定义以下委托方法,使用共享的 UIApplication 实例来获取该委托的引用SomeAppDelegate *appDelegate = (SomeAppDe

16、legate *)UIApplication sharedApplication delegate;_anotherViewController = appDelegate._anotherViewController; UIViewController 内建 Table View纯代码在 UIViewController 控制器内建 Table Viewinterface RootViewController : UIViewController NSArray *timeZoneNames;property (nonatomic,retain) NSArray *timeZoneNames

17、;end(void) loadViewUITableView *tableView = UITableView alloc initWithFrame:UIScreen mainScreen applicationFrame style: UITableViewStylePlain;tableView.autoresizingMask = (UIViewAutoresizingFlexibleHeight | UIViewAutoresizingWidth);tableView.delegate = self;tableView.dataSource = self;tableView relo

18、adData;self.view = tableView;tableView release;将 plist 文件中的数据赋给数组NSString *thePath = NSBundle mainBundle pathForResource:“States“ ofType:“plist“;NSArray *array = NSArray arrayWithContentsOfFile:thePath;UITouch手指的触摸范围:64X64 #pragma mark -#pragma mark Touch Events- (void)touchesBegan:(NSSet *) touches

19、 withEvent:(UIEvent *) event originFrame = bookCover.frame;NSLog(“%s %d“, _FUNCTION_,_LINE_);if (touches count = 2) NSArray *twoTouches = touches allObjects;UITouch *firstTouch = twoTouches objectAtIndex:0;UITouch *secondTouch = twoTouches objectAtIndex:1;CGPoint firstPoint = firstTouch locationInVi

20、ew:bookCover;CGPoint secondPoint = secondTouch locationInView:bookCover;CGFloat deltaX = secondPoint.x - firstPoint.x;CGFloat deltaY = secondPoint.y - firstPoint.y; initialDistance = sqrt(deltaX * deltaX + deltaY * deltaY ); frameX = bookCover.frame.origin.x;frameY = bookCover.frame.origin.y;frameW

21、= bookCover.frame.size.width;frameH = bookCover.frame.size.height;NSLog(“%s %d“, _FUNCTION_,_LINE_);- (void)touchesMoved:(NSSet *) touches withEvent:(UIEvent *) event if(touches count = 2) NSLog(“%s %d“, _FUNCTION_,_LINE_);NSArray *twoTouches = touches allObjects;UITouch *firstTouch = twoTouches obj

22、ectAtIndex:0;UITouch *secondTouch = twoTouches objectAtIndex:1;CGPoint firstPoint = firstTouch locationInView:bookCover;CGPoint secondPoint = secondTouch locationInView:bookCover;CGFloat deltaX = secondPoint.x - firstPoint.x;CGFloat deltaY = secondPoint.y - firstPoint.y; CGFloat currentDistance = sq

23、rt(deltaX * deltaX + deltaY * deltaY ); if (initialDistance = 0) initialDistance = currentDistance;else if (currentDistance != initialDistance)CGFloat changedDistance = currentDistance - initialDistance;NSLog(“changedDistance = %f“,changedDistance);bookCover setFrame:CGRectMake(frameX - changedDista

24、nce / 2, frameY - (changedDistance * frameH) / (2 * frameW),frameW + changedDistance, frameH + (changedDistance * frameH) / frameW);- (void)touchesEnded:(NSSet *) touches withEvent:(UIEvent *) event UITouch *touch = touches anyObject;UITouch 双击图片变大/还原if (touch tapCount = 2) NSLog(“%s %d“, _FUNCTION_

25、,_LINE_);if (!flag) bookCover setFrame:CGRectMake(bookCover.frame.origin.x - bookCover.frame.size.width / 2,bookCover.frame.origin.y - bookCover.frame.size.height / 2,2 * bookCover.frame.size.width, 2 * bookCover.frame.size.height);flag = YES;else bookCover setFrame:CGRectMake(bookCover.frame.origin

26、.x + bookCover.frame.size.width / 4, bookCover.frame.origin.y + bookCover.frame.size.height / 4,bookCover.frame.size.width / 2, bookCover.frame.size.height / 2); flag = NO; Get the Location of Touches(CGPoint)locationInView:(UIView *)view(CGPoint)previousLocationInView:(UIView *)viewview windowGetting Touch AttributestapCount(read only) timestamp(read only) phase(read only)

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育教学资料库 > 精品笔记

Copyright © 2018-2021 Wenke99.com All rights reserved

工信部备案号浙ICP备20026746号-2  

公安局备案号:浙公网安备33038302330469号

本站为C2C交文档易平台,即用户上传的文档直接卖给下载用户,本站只是网络服务中间平台,所有原创文档下载所得归上传人所有,若您发现上传作品侵犯了您的权利,请立刻联系网站客服并提供证据,平台将在3个工作日内予以改正。