你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS 5新增API介紹及使用

IOS 5新增API介紹及使用

編輯:IOS開發綜合

1.UIStepper

 

 

[cpp]
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(200, 100, 0, 0)]; 
    [stepper sizeToFit]; 
    stepper.value = 0; 
    stepper.minimumValue = 0; 
    stepper.maximumValue = 1; 
    stepper.stepValue = 0.1; 
    [stepper addTarget:self action:@selector(stepperAction:) forControlEvents:UIControlEventValueChanged]; 
    [self.view addSubview:stepper]; 
    [stepper release]; 

UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(200, 100, 0, 0)];
    [stepper sizeToFit];
    stepper.value = 0;
    stepper.minimumValue = 0;
    stepper.maximumValue = 1;
    stepper.stepValue = 0.1;
    [stepper addTarget:self action:@selector(stepperAction:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:stepper];
    [stepper release];[cpp] view plaincopyprint?
- (void)stepperAction:(UIStepper *)stepper 

    NSLog(@"stepper value:%f",stepper.value); 

- (void)stepperAction:(UIStepper *)stepper
{
    NSLog(@"stepper value:%f",stepper.value);
}
2.UIAlertView樣式

 


[cpp] 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"Hello World" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil]; 
//第一張圖    alert.alertViewStyle = UIAlertViewStylePlainTextInput;  
//第二張圖    alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;  
//第三張圖    alert.alertViewStyle = UIAlertViewStyleSecureTextInput;  
    [alert show]; 
    [alert release]; 

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"Hello World" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
//第一張圖    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
//第二張圖    alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
//第三張圖    alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
    [alert show];
    [alert release];[cpp] view plaincopyprint?
//返回指定索引值的TextField ,這個API僅存在於IOS5.0以上  
- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex 

    return textField; 

//返回指定索引值的TextField ,這個API僅存在於IOS5.0以上
- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex
{
    return textField;
}3 UIScreen調節亮度
[cpp]
UIScreen *mainScreen = [UIScreen mainScreen]; 
    //設置屏幕亮度為50%  
    mainScreen.brightness = 0.5; 
    //默認是NO。如果YES,可以通過wantsSoftwareDimming屬性來聲明此應用需要將屏幕亮度調整到比中等亮度偏暗的級別。(需要注意的是,打開wantsSoftwareDimming可能會對性能有影響,因為這種昏暗是通過軟件來實現的。)  
    mainScreen.wantsSoftwareDimming = YES; 

UIScreen *mainScreen = [UIScreen mainScreen];
    //設置屏幕亮度為50%
    mainScreen.brightness = 0.5;
    //默認是NO。如果YES,可以通過wantsSoftwareDimming屬性來聲明此應用需要將屏幕亮度調整到比中等亮度偏暗的級別。(需要注意的是,打開wantsSoftwareDimming可能會對性能有影響,因為這種昏暗是通過軟件來實現的。)
    mainScreen.wantsSoftwareDimming = YES;4 UIReferenceLibraryViewController顯示詞語解釋

\
[cpp] 
NSString *key = @"hello"; 
    //判斷任何已經安裝的字典裡有key的定義  
    if ([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:key]) 
    { 
        UIReferenceLibraryViewController *controller = [[UIReferenceLibraryViewController alloc] initWithTerm:key]; 
        //只是切換方式  
        [controller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; 
        [self presentModalViewController:controller animated:YES]; 
        [controller release]; 
    } 

NSString *key = @"hello";
    //判斷任何已經安裝的字典裡有key的定義
    if ([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:key])
    {
        UIReferenceLibraryViewController *controller = [[UIReferenceLibraryViewController alloc] initWithTerm:key];
        //只是切換方式
        [controller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
        [self presentModalViewController:controller animated:YES];
        [controller release];
    }5.UISplitViewController delegate,顯示隱藏時delegate

UISplitViewController
[cpp] 
//這個delegate方法是被發送到你的delegate詢問在特定方向下你想要左側做什麼,因此它把自己傳遞給你,還有左側,它會問在這個方向你想要我對左側做什麼。要隱藏就返回YES,要保留在屏幕上就返回NO  
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation 

    return YES; 

//這個delegate方法是被發送到你的delegate詢問在特定方向下你想要左側做什麼,因此它把自己傳遞給你,還有左側,它會問在這個方向你想要我對左側做什麼。要隱藏就返回YES,要保留在屏幕上就返回NO
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation
{
    return YES;
}6.從xib文件中獲取cell
創建UITableViewCell
[cpp] 
//為tableview注冊一個nib  
    UINib *nib = [UINib nibWithNibName:@"MyCell" bundle:nil]; 
    [self.tableView registerNib:nib forCellReuseIdentifier:@"identifier"]; 

//為tableview注冊一個nib
    UINib *nib = [UINib nibWithNibName:@"MyCell" bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:@"identifier"];[cpp] view plaincopyprint?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

    //重用前面注冊過的cell  
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"]; 
//other code  
return cell; 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //重用前面注冊過的cell
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"];
//other code
return cell;
}7 UIImage,image動畫


8 UIAppearance應用於全部屬性
IOS 5下強大的UI修改工具—— UIAppearance

[cpp] 
//程序中所有slider改為紅色  
    [[UISlider appearance] setMinimumTrackTintColor:[UIColor redColor]]; 

//程序中所有slider改為紅色
    [[UISlider appearance] setMinimumTrackTintColor:[UIColor redColor]];9 UIPageViewController
UIPageViewController-淺析
控件為我們提供了一種像翻書效果的一種控件。我們可以通過使用UIPageViewController控件,來完成類似圖書一樣的翻頁控制方式。

 

10 UIDocument
iPhone開發 - iCloud開發准備

支持iCloud簡記

 

11 管理資源庫
ALAssetsLibrary-代碼操作iOS相冊資源

ALAssetsLibrary提供了我們對iOS設備中的相片、視頻的訪問。

 

可以通過valueForProperty獲取到圖片的信息,包括類型, Location , 時長,方向,日期,格式 , URL地址。

[cpp] 
self.view.backgroundColor = [UIColor whiteColor]; 
    self.assetsLibrary = [[ALAssetsLibrary alloc] init]; 
    dispatch_queue_t dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); 
    dispatch_async(dispatchQueue, ^(void) 
    { 
        // 遍歷所有相冊  
        [self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll 
                                          usingBlock:^(ALAssetsGroup *group, BOOL *stop) 
        { 
              // 遍歷每個相冊中的項ALAsset  
              [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index,BOOL *stop) 
               { 
                   
                  __block BOOL foundThePhoto = NO; 
                  if (foundThePhoto) 
                  { 
                      *stop = YES; 
                  } 
                  // ALAsset的類型  
                  NSString *assetType = [result valueForProperty:ALAssetPropertyType]; 
                   //如果是照片的話  
                   //ALAssetTypeVideo  
                   //ALAssetTypeUnknown  
                  if ([assetType isEqualToString:ALAssetTypePhoto]) 
                  { 
                      foundThePhoto = YES; 
                      *stop = YES; 
                      //封裝了ALAsset,包含了一個資源文件中的很多屬性。(可以說是ALAsset的不同的表示方式,本質上都表示同一個資源文件)  
                      ALAssetRepresentation *assetRepresentation = [result defaultRepresentation]; 
                      CGFloat imageScale = [assetRepresentation scale]; 
                      UIImageOrientation imageOrientation = (UIImageOrientation)[assetRepresentation orientation]; 
                      dispatch_async(dispatch_get_main_queue(), ^(void) 
                      { 
                          CGImageRef imageReference = [assetRepresentation fullResolutionImage]; 
                          // 對找到的圖片進行操作  
                          UIImage *image = [[UIImage alloc] initWithCGImage:imageReference scale:imageScale orientation:imageOrientation]; 
                          if (image != nil) 
                          { 
                              //呈現  
                              self.imageView = [[UIImageView alloc] initWithFrame:self.view.bounds]; 
                              self.imageView.contentMode = UIViewContentModeScaleAspectFit; 
                              self.imageView.image = image; 
                              [self.view addSubview:self.imageView]; 
                          } else 
                          { 
                              NSLog(@"Failed to create the image."); 
                          } 
                      }); 
                  } 
              }]; 
          } 
        failureBlock:^(NSError *error) 
        { 
            //讀取失敗的處理  
        }]; 
    }); 

self.view.backgroundColor = [UIColor whiteColor];
    self.assetsLibrary = [[ALAssetsLibrary alloc] init];
    dispatch_queue_t dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_async(dispatchQueue, ^(void)
    {
        // 遍歷所有相冊
        [self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll
                                          usingBlock:^(ALAssetsGroup *group, BOOL *stop)
        {
              // 遍歷每個相冊中的項ALAsset
              [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index,BOOL *stop)
               {
                 
                  __block BOOL foundThePhoto = NO;
                  if (foundThePhoto)
                  {
                      *stop = YES;
                  }
                  // ALAsset的類型
                  NSString *assetType = [result valueForProperty:ALAssetPropertyType];
                   //如果是照片的話
                   //ALAssetTypeVideo
                   //ALAssetTypeUnknown
                  if ([assetType isEqualToString:ALAssetTypePhoto])
                  {
                      foundThePhoto = YES;
                      *stop = YES;
                      //封裝了ALAsset,包含了一個資源文件中的很多屬性。(可以說是ALAsset的不同的表示方式,本質上都表示同一個資源文件)
                      ALAssetRepresentation *assetRepresentation = [result defaultRepresentation];
                      CGFloat imageScale = [assetRepresentation scale];
                      UIImageOrientation imageOrientation = (UIImageOrientation)[assetRepresentation orientation];
                      dispatch_async(dispatch_get_main_queue(), ^(void)
                      {
                          CGImageRef imageReference = [assetRepresentation fullResolutionImage];
                          // 對找到的圖片進行操作
                          UIImage *image = [[UIImage alloc] initWithCGImage:imageReference scale:imageScale orientation:imageOrientation];
                          if (image != nil)
                          {
                              //呈現
                              self.imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
                              self.imageView.contentMode = UIViewContentModeScaleAspectFit;
                              self.imageView.image = image;
                              [self.view addSubview:self.imageView];
                          } else
                          {
                              NSLog(@"Failed to create the image.");
                          }
                      });
                  }
              }];
          }
        failureBlock:^(NSError *error)
        {
            //讀取失敗的處理
        }];
    });
12 GLKit
如何為iOS5創建一個簡單GLKit應用程序

 

13 Core Image
iOS5新特性:強大的Core Image

 

14 Core Data
[Cocoa]深入淺出 Cocoa 之 Core Data(1)- 框架詳解

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved