成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

iOS開發筆記

移動開發 iOS
作為iOS開發者,大家獲取對它的基礎知識有了些了解,但是對于它所深入的東西或許有的還接觸不到,下面,就將技術大牛整理好的開發筆記奉獻給大家。

退回輸入鍵盤:

  1.  - (BOOL) textFieldShouldReturn:(id)textField{  
  2.     [textField  resignFirstResponder];  
  3. }   

CGRect

CGPoint & CGSize

  1. CGPoint aPoint = CGPointMake(x, y);    CGSize aSize = CGSizeMake(width, height);   

設置透明度

  1. [myView setAlpha:value];   (0.0 < value < 1.0)   

 

 

 

 

設置背景色

  1. [myView setBackgroundColor:[UIColor redColor]];  
  2.    (blackColor;darkGrayColor;lightGrayColor;whiteColor;grayColor; redColor; greenColor; blueColor; cyanColor;yellowColor;magentaColor;  
  3. orangeColor;purpleColor;brownColor; clearColor; )   

自定義顏色:

  1. UIColor *newColor = [[UIColor alloc] initWithRed:(float) green:(float) blue:(float) alpha:(float)];      0.0~1.0   

寬度和高度

1
768X1024     1024X768    狀態欄高 20 像素高   導航欄 工具欄 44像素高

隱藏狀態欄:

  1. [[UIApplication shareApplication] setStatusBarHidden: YES animated:NO]   

橫屏:

  1. [[UIApplication shareApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight].  
  2. orientation == UIInterfaceOrientationLandscapeLeft  
  3. window=[[UIWindow alloc] initWithFrame:[UIScreen mainScreen] bounds];全屏   

自動適應父視圖大小:

  1. aView.autoresizingSubviews = YES;  
  2. aView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);   

定義按鈕

  1.  UIButton *scaleUpButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];  
  2. [scaleUpButton setTitle:@"放 大"forState:UIControlStateNormal];  
  3. scaleUpButton.frame = CGRectMake(40, 420, 100, 40);  
  4. [scaleUpButton addTarget:self action:@selector(scaleUp) forControlEvents:UIControlEventTouchUpInside];   

設置視圖背景圖片

  1. UIImageView *aView;  
  2. [aView setImage:[UIImage imageNamed:@”name.png”]];  
  3. view1.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"image1.png"]];  
  4.    
  5. UISlider *slider = (UISlider *) sender;  
  6. NSString *newText = [[NSString alloc] initWithFormat:@”%d”, (int)(slider.value + 0.5f)];  
  7. label.text = newText;   

活動表單 <UIActionSheetDelegate>

  1. - (IBActive) someButtonPressed:(id) sender  
  2. {  
  3.     UIActionSheet *actionSheet = [[UIActionSheet alloc]  
  4.                     initWithTitle:@”Are you sure?”  
  5.                     delegate:self  
  6.                     cancelButtonTitle:@”No way!”  
  7.                     destructiveButtonTitle:@”Yes, I’m Sure!”  
  8.                     otherButtonTitles:nil];  
  9.     [actionSheet showInView:self.view];  
  10.     [actionSheet release];  
  11. }   

警告視圖 <UIAlertViewDelegate>

  1.   - (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger) buttonIndex  
  2. {  
  3.      if(buttonIndex != [actionSheet cancelButtonIndex])  
  4.      {  
  5.           NSString *message = [[NSString alloc] initWithFormat:@”You can  
  6.                    breathe easy, everything went OK.”];  
  7.           UIAlertView *alert = [[UIAlertView alloc]  
  8.                                initWithTitle:@”Something was done”  
  9.                                 message:message  
  10.                                 delegate:self  
  11.                                 cancelButtonTitle:@”OK”  
  12.                                 otherButtonTitles:nil];  
  13.           [alert show];  
  14.           [alert release];  
  15.           [message release];  
  16.      }  
  17. }   

動畫效果

  1.  -(void)doChange:(id)sender  
  2. {  
  3. if(view2 == nil)  
  4. {  
  5. [self loadSec];  
  6. }  
  7. [UIView beginAnimations:nil context:NULL];  
  8. [UIView setAnimationDuration:1];  
  9. [UIView setAnimationTransition:([view1 superview] ? UIViewAnimationTransitionFlipFromLeft : UIViewAnimationTransitionFlipFromRight)forView : self.view cache:YES];  
  10.    
  11.     if([view1 superview]!= nil)  
  12. {  
  13. [view1 removeFromSuperview];  
  14. [self.view addSubview:view2];  
  15.    
  16. }else{  
  17.    
  18. [view2 removeFromSuperview];  
  19. [self.view addSubview:view1];  
  20. }  
  21. [UIView commitAnimations];  
  22. }   

Table View <UITableViewDateSource>

  1.  
  2.  #pragma mark -  
  3. #pragma mark Table View Data Source Methods  
  4. //指定分區中的行數,默認為1  
  5. - (NSInteger)tableView:(UITableView *)tableView  
  6.  numberOfRowsInSection:(NSInteger)section  
  7. {  
  8. return[self.listDatacount];  
  9. }  
  10.    
  11. //設置每一行cell顯示的內容  
  12. - (UITableViewCell *)tableView:(UITableView *)tableView  
  13. cellForRowAtIndexPath:(NSIndexPath *)indexPath  
  14. {  
  15. staticNSString *SimpleTableIndentifier = @"SimpleTableIndentifier";  
  16. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIndentifier];  
  17. if(cell == nil) {  
  18. cell = [[[UITableViewCell alloc]  
  19. initWithStyle:UITableViewCellStyleSubtitle  
  20. reuseIdentifier:SimpleTableIndentifier]  
  21. autorelease];  
  22. }  
  23.      UIImage *image = [UIImage imageNamed:@"13.gif"];  
  24. cell.imageView.image = image;  
  25.    
  26. NSUInteger row = [indexPath row];  
  27. cell.textLabel.text = [listData objectAtIndex:row];  
  28.      cell.textLabel.font = [UIFont boldSystemFontOfSize:20];  
  29.    
  30.      if(row < 5)  
  31. cell.detailTextLabel.text = @"Best friends";  
  32. else  
  33.     cell.detailTextLabel.text = @"friends";  
  34. returncell;  
  35. }   

圖像:如果設置圖像,則它顯示在文本的左側

文本標簽:這是單元的主要文本(UITableViewCellStyleDefault 只顯示文本標簽)

詳細文本標簽:這是單元的輔助文本,通常用作解釋性說明或標簽

  1.  
  2.  
  3.   
  4.  
  5.  UITableViewCellStyleSubtitle  
  6. UITableViewCellStyleDefault  
  7. UITableViewCellStyleValue1  
  8. UITableViewCellStyleValue2  
  9.    
  10. <UITableViewDelegate>  
  11. #pragma mark -  
  12. #pragma mark Table View Delegate Methods  
  13. //把每一行縮進級別設置為其行號  
  14. - (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath  
  15. {  
  16. NSUInteger row = [indexPath row];  
  17. returnrow;  
  18. }  
  19. //獲取傳遞過來的indexPath值  
  20. - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath  
  21. {  
  22. NSUInteger row = [indexPath row];  
  23. if(row == 0)  
  24. returnnil;  
  25. returnindexPath;  
  26. }  
  27.    
  28. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  
  29. {  
  30. NSUInteger row = [indexPath row];  
  31. NSString *rowValue = [listData objectAtIndex:row];  
  32. NSString *message = [[NSString alloc] initWithFormat:@"You selected %@",rowValue];  
  33. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Row Selected"  
  34. message:message  
  35.     delegate:nil  
  36.   cancelButtonTitle:@"Yes, I did!"  
  37.   otherButtonTitles:nil];  
  38. [alert show];  
  39. [alert release];  
  40. [message release];  
  41. [tableView deselectRowAtIndexPath:indexPath animated:YES];  
  42. }  
  43.    
  44. //設置行的高度  
  45. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath  
  46. {  
  47. return40;  
  48. }   

隨機數的使用

 

  1. 頭文件的引用 
  2. #import <time.h> 
  3. #import <mach/mach_time.h> 
  4.   
  5. srandom()的使用 
  6. srandom((unsigned)(mach_absolute_time() & 0xFFFFFFFF)); 
  7.   
  8. 直接使用 random() 來調用隨機數 

在UIImageView 中旋轉圖像

  1. float rotateAngle = M_PI;  
  2. CGAffineTransform transform =CGAffineTransformMakeRotation(rotateAngle);  
  3. imageView.transform = transform;   

以上代碼旋轉imageView, 角度為rotateAngle, 方向可以自己測試哦!

在Quartz中如何設置旋轉點

  1. UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.png"]];  
  2. imageView.layer.anchorPoint = CGPointMake(0.5, 1.0);   

這個是把旋轉點設置為底部中間。記住是在QuartzCore.framework中才得到支持。

#p#

創建.plist文件并存儲

  1.   
  2.  NSString *errorDesc; //用來存放錯誤信息  
  3. NSMutableDictionary *rootObj = [NSMutableDictionary dictionaryWithCapacity:4];//NSDictionary, NSData等文件可以直接轉化為plist文件  
  4. NSDictionary *innerDict;  
  5. NSString *name;  
  6. Player *player;  
  7. NSInteger saveIndex;  
  8.    
  9. for(int i = 0; i < [playerArraycount]; i++) {  
  10.       player = nil;  
  11.       player = [playerArray objectAtIndex:i];  
  12.       if(player == nil)  
  13.              break;  
  14.       name = player.playerName;// This “Player1″ denotes the player name could also be the computer name  
  15.       innerDict = [self getAllNodeInfoToDictionary:player];  
  16.       [rootObj setObject:innerDict forKey:name];// This “Player1″ denotes the person who start this game  
  17. }  
  18. player = nil;  
  19. NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:(id)rootObj format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];   

***2行可以忽略,只是給rootObj添加一點內容。這個plistData為創建好的plist文件,用其writeToFile方法就可以寫成文件。下面是代碼:

  1.  
  2. 17  /*得到移動設備上的文件存放位置*/  
  3.         NSString *documentsPath = [self getDocumentsDirectory];  
  4.         NSString *savePath = [documentsPath stringByAppendingPathComponent:@"save.plist"];  
  5.    
  6.         /*存文件*/  
  7.         if(plistData) {  
  8.                 [plistData writeToFile:savePath atomically:YES];  
  9.          }  
  10.          else{  
  11.                 NSLog(errorDesc);  
  12.                 [errorDesc release];  
  13.         }  
  14.    
  15.         - (NSString *)getDocumentsDirectory {  
  16.                 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
  17.                 return[paths objectAtIndex:0];  
  18.         }   

讀取plist文件并轉化為NSDictionary

  1.   
  2. NSString *documentsPath = [self getDocumentsDirectory];  
  3. NSString *fullPath = [documentsPath stringByAppendingPathComponent:@"save.plist"];  
  4. NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:fullPath];   

讀取一般性文檔文件

  1. NSString *tmp;  
  2. NSArray *lines;/*將文件轉化為一行一行的*/  
  3. lines = [[NSString    stringWithContentsOfFile:@"testFileReadLines.txt"]  
  4.                componentsSeparatedByString:@”\n”];  
  5.    
  6.  NSEnumerator *nse = [lines objectEnumerator];  
  7.    
  8.  // 讀取<>里的內容  
  9.  while(tmp = [nse nextObject]) {  
  10.           NSString *stringBetweenBrackets = nil;  
  11.           NSScanner *scanner = [NSScanner scannerWithString:tmp];  
  12.           [scanner scanUpToString:@"<"intoString:nil];  
  13.           [scanner scanString:@"<"intoString:nil];  
  14.           [scanner scanUpToString:@">"intoString:&stringBetweenBrackets];  
  15.    
  16.           NSLog([stringBetweenBrackets description]);  
  17.   }   

對于讀寫文件,還有補充,暫時到此。隨機數和文件讀寫在游戲開發中經常用到。所以把部分內容放在這,以便和大家分享,也當記錄,便于查找。

隱藏NavigationBar

  1. [self.navigationController setNavigationBarHidden:YES animated:YES];   

在想隱藏的ViewController中使用就可以了。

如果無法保證子類行為的一致性,那么就用委托

  1. If the subClass cann’t keep with superClass,use delegate rather than inheritance.  

屏幕上看到的,都是UIVew

  1. Everything you see on Screen is UIView.  

如果對性能要求高,慎用Interface Build

  1. if application’s performance is important,be discreet for the interface build.  

copy是創建,retain是引用

  1. the copy operation is create a new one,but the retain operation is just a reference.  

alloc需要release,convenient不需要release

  1. alloc method need corresponding release method,but convenient method not.  

加載到NSArray/NSMutableArray里的對象,不需要負責release

  1. The objects added to NSArray/NSMutableArray need not to be released.  

IBOutlet,IBAction為你開啟了訪問Interface Build中對象的大門

  1. IBOutlet and IBAction open the door to access the objects in Interface build.  

UIApplicationDelegate負責應用程序的生命周期,而UIViewController負責View的生命周期

  1. UIApplicationDelegate is responsible for the application life cycle,but UIViewController for the UIView.  

為了程序的健壯性,請盡量實現Delegate的生命周期函數

  1. if you want to develop a robust application,implement the life cycle methods as more as possbile.  

you觸摸的不是UIEvent,而是NSSet的UIView

  1. what you touch on screen is not UIEvent but UIView  

UITextField不響應鍵盤:

  1. 方法1: TextField的的Touch Cancel響應中,添加[textFied resignFirstResponder];  
  2.    
  3.     方法: - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{  
  4.    
  5. [textFied resignFirstResponder]; }   

更改響應鍵盤return按鈕:

  1. TextField.returnKeyType=UIReturnKeyDone;  
  2. select:  
  3.    UIReturnKeyDefault,  
  4.    UIReturnKeyGo,  
  5.    UIReturnKeyGoogle,  
  6.    UIReturnKeyJoin,  
  7.    UIReturnKeyNext,  
  8.    UIReturnKeyRoute,  
  9.    UIReturnKeySearch,  
  10.    UIReturnKeySend,  
  11.    UIReturnKeyYahoo,  
  12.    UIReturnKeyDone,  
  13.    UIReturnKeyEmergencyCall,   

尺寸問題:

 

  1. iPhone應用程序圖標大小:57*57; 
  2.   
  3. iPhone全屏UIView大小:320*460 添加UITabBar后大小:320*411 
  4.   
  5. UITabelViewCell默認大小: 320*44 

繪制控件方法

  1.  
  2.   //--alloc  
  3. -(UITextField *)GetDefaultTextField:(CGRect)frame{  
  4.    
  5.     UITextField *textField=[[UITextField alloc] initWithFrame:frame];  
  6.     textField.borderStyle=UITextBorderStyleRoundedRect;  
  7.     textField.font=[UIFont fontWithName:@"Arial"size:12.0];  
  8.     textField.textAlignment=UITextAlignmentCenter;  
  9.     textField.contentVerticalAlignment=UIControlContentVerticalAlignmentCenter;  
  10.     textField.keyboardType=UIKeyboardTypeNumbersAndPunctuation;  
  11.     textField.returnKeyType=UIReturnKeyDone;  
  12.     textField.delegate=self;  
  13.     returntextField;  
  14.    
  15. }  
  16. //--alloc  
  17. -(UILabel *)GetDefaultLabel:(CGRect)frame{  
  18.    
  19.     UILabel *label = [[UILabel alloc] initWithFrame: frame];  
  20.     label.textAlignment=UITextAlignmentCenter;  
  21.     label.textColor=[UIColor blackColor];  
  22.     label.backgroundColor=[UIColor clearColor];  
  23.     label.font=[UIFont boldSystemFontOfSize:12.0];  
  24.     returnlabel;  
  25. }  
  26. //--alloc  
  27. -(UIButton *)GetDefaultButton:(CGRect)frame{  
  28.    
  29.     UIButton *button=[[UIButton alloc] initWithFrame:frame];  
  30.     [button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];  
  31.     [button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];  
  32.     [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];  
  33.     [button.titleLabel setFont:[UIFont boldSystemFontOfSize:14.0]];  
  34.     [button.titleLabel setLineBreakMode:UILineBreakModeCharacterWrap];  
  35.     [button addTarget:self action:@selector(btnTradeTouchUpInside:) forControlEvents:UIControlEventTouchUpInside];  
  36.     [button setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];  
  37.    
  38.                 [button setBackgroundImage:[UIImage imageNamed:@"png1.png"] forState:UIControlStateNormal];  
  39.                 [button setBackgroundColor:[UIColor lightGrayColor]];  
  40.                 button.tag=kButtonTag;  
  41.    
  42.      returnbutton;}   

多使用宏定義常量。tag,frame大小,一些判斷標志位。

1
#define kIndexValueTag 1

蘋果屏幕截圖快捷鍵

一般在Mac上用Command-Shif-3/4來截圖。注:Command=蘋果鍵 其實還有幾個輔助鍵,來起到不同的截圖功能……

 

  1. 1)Command-Shift-3(適用于OS9,10.1X和10.2) 
  2. 將整個屏幕拍下并保存到桌面。 
  3. 2)Command-Shift-4(適用于OS9,10.1X和10.2) 
  4. 將屏幕的一部分拍下并保存到桌面。當按下著幾個鍵后,光標會變為一個十字,可以拖拉來選取拍報區域。 
  5. 3)Command-Shift-Control-3(適用于OS9和10.2) 
  6. 將整個屏幕拍下并保存到剪貼板,可以Command+V直接粘貼到如Photoshop等軟件中編輯。 
  7. 4)Command-Shift-Control-4(適用于OS9和10.2) 
  8. 將屏幕的一部分拍下并保存到剪貼板。 
  9. 5)Command-Shift-4再按空格鍵(適用于10.2) 
  10. 光標會變成一個照相機,點擊可拍下當前窗口或菜單或Dock以及圖標等,只要將照相機移動到不用區域(有效區域會顯示為淺藍色)點擊。 
  11. 6)Command-Shift-Control-4再按空格鍵(適用于10.2) 
  12. 將選取的窗口或其他區域的快照保存到剪貼板。 
  13. 7)Command-Shift-Capslock-4(適用于OS9) 
  14. 將當前的窗口拍下并保存到桌面。 
  15. 8)Command-Shift-Capslock-Control-4(適用于OS9) 
  16. 將當前的窗口拍下并保存到剪貼板。 
責任編輯:張葉青 來源: 開源社區
相關推薦

2015-10-14 10:16:26

安安卓開發EventBus

2012-05-17 11:45:12

iPhone

2021-11-11 17:36:07

鴻蒙HarmonyOS應用

2022-08-15 22:09:37

設備開發開發筆記

2011-08-03 10:49:46

2009-06-17 14:33:08

java項目開發

2021-02-03 09:59:02

鴻蒙HarmonyOS應用開發

2022-08-09 07:57:25

Linux操作系統Windows

2011-08-22 15:43:08

IOS開發數據庫

2011-08-16 14:59:31

IOS開發ViewDidUnloiOS 5

2011-08-03 09:44:18

IOS開發 UITextFiel UITableVie

2011-08-09 16:08:58

IOS游戲Cocos2d

2015-09-28 11:23:09

iOS8iOS 9 開發

2013-03-28 09:45:34

iOS學習筆記總結整理

2012-05-14 16:59:40

iOS

2011-08-17 13:27:08

iPhone游戲開發objective-c

2014-07-29 13:25:43

WWDC 2014 S

2011-07-08 18:28:43

iOS 接口

2013-07-29 04:46:48

iOS開發iOS開發學習iOS小知識

2011-05-11 10:02:37

iOS
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产精品视频在线播放 | 欧美成人一区二免费视频软件 | 激情av| 国产精品99久久久精品免费观看 | 精品一区二区三区在线观看 | 亚洲精品一 | 91精品国产欧美一区二区成人 | 九九九色 | 男人阁久久 | 欧美一级全黄 | 国产视频二区 | 91精品久久久久久久久 | 99pao成人国产永久免费视频 | 天天躁日日躁aaaa视频 | 91久久国产综合久久91精品网站 | 羞羞免费网站 | 男女深夜网站 | 999观看免费高清www | 女女百合av大片一区二区三区九县 | 成人黄色在线 | 狠狠爱一区二区三区 | 亚洲精品久久久久中文字幕二区 | 日本黄色的视频 | 亚洲精品久久视频 | 91超碰在线观看 | 超碰97免费在线 | a免费观看 | 91免费在线| 欧美激情精品久久久久久变态 | 狠狠操av| 天天澡天天狠天天天做 | 91在线最新 | 日本午夜免费福利视频 | 久久国产三级 | 国产在线精品一区二区三区 | 国产高清av免费观看 | 亚洲欧美久久 | 精品久久久久久亚洲精品 | 免费观看av | 羞羞视频免费观看入口 | 国产欧美日韩久久久 |