IOS 5新增API介绍及使用

来源:互联网 发布:网络直播你怎么看即评 编辑:程序博客网 时间:2024/04/28 07:28

本文原始地址:IOS 5新增API介绍及使用

1.UIStepper 


[cpp] view plaincopyprint?
  1. UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(200, 100, 0, 0)];  
  2.     [stepper sizeToFit];  
  3.     stepper.value = 0;  
  4.     stepper.minimumValue = 0;  
  5.     stepper.maximumValue = 1;  
  6.     stepper.stepValue = 0.1;  
  7.     [stepper addTarget:self action:@selector(stepperAction:) forControlEvents:UIControlEventValueChanged];  
  8.     [self.view addSubview:stepper];  
  9.     [stepper release];  
[cpp] view plaincopyprint?
  1. - (void)stepperAction:(UIStepper *)stepper  
  2. {  
  3.     NSLog(@"stepper value:%f",stepper.value);  
  4. }  

2.UIAlertView样式

[cpp] view plaincopyprint?
  1.     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"Hello World" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];  
  2. //第一张图    alert.alertViewStyle = UIAlertViewStylePlainTextInput;  
  3. //第二张图    alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;  
  4. //第三张图    alert.alertViewStyle = UIAlertViewStyleSecureTextInput;  
  5.     [alert show];  
  6.     [alert release];  
[cpp] view plaincopyprint?
  1. //返回指定索引值的TextField ,这个API仅存在于IOS5.0以上  
  2. - (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex  
  3. {  
  4.     return textField;  
  5. }  
3 UIScreen调节亮度
[cpp] view plaincopyprint?
  1. UIScreen *mainScreen = [UIScreen mainScreen];  
  2.     //设置屏幕亮度为50%  
  3.     mainScreen.brightness = 0.5;  
  4.     //默认是NO。如果YES,可以通过wantsSoftwareDimming属性来声明此应用需要将屏幕亮度调整到比中等亮度偏暗的级别。(需要注意的是,打开wantsSoftwareDimming可能会对性能有影响,因为这种昏暗是通过软件来实现的。)  
  5.     mainScreen.wantsSoftwareDimming = YES;  
4 UIReferenceLibraryViewController显示词语解释

[cpp] view plaincopyprint?
  1. NSString *key = @"hello";  
  2.     //判断任何已经安装的字典里有key的定义  
  3.     if ([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:key])  
  4.     {  
  5.         UIReferenceLibraryViewController *controller = [[UIReferenceLibraryViewController alloc] initWithTerm:key];  
  6.         //只是切换方式  
  7.         [controller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];  
  8.         [self presentModalViewController:controller animated:YES];  
  9.         [controller release];  
  10.     }  
5.UISplitViewController delegate,显示隐藏时delegate
UISplitViewController
[cpp] view plaincopyprint?
  1. //这个delegate方法是被发送到你的delegate询问在特定方向下你想要左侧做什么,因此它把自己传递给你,还有左侧,它会问在这个方向你想要我对左侧做什么。要隐藏就返回YES,要保留在屏幕上就返回NO  
  2. - (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation  
  3. {  
  4.     return YES;  
  5. }  
6.从xib文件中获取cell
创建UITableViewCell
[cpp] view plaincopyprint?
  1. //为tableview注册一个nib  
  2.     UINib *nib = [UINib nibWithNibName:@"MyCell" bundle:nil];  
  3.     [self.tableView registerNib:nib forCellReuseIdentifier:@"identifier"];  
[cpp] view plaincopyprint?
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  
  2. {  
  3.     //重用前面注册过的cell  
  4.     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"];  
  5. //other code  
  6. return cell;  
  7. }  
7 UIImage,image动画

8 UIAppearance应用于全部属性
IOS 5下强大的UI修改工具—— UIAppearance
[cpp] view plaincopyprint?
  1. //程序中所有slider改为红色  
  2.     [[UISlider appearance] setMinimumTrackTintColor:[UIColor redColor]];  
9 UIPageViewController
UIPageViewController-浅析
控件为我们提供了一种像翻书效果的一种控件。我们可以通过使用UIPageViewController控件,来完成类似图书一样的翻页控制方式。

10 UIDocument
iPhone开发 - iCloud开发准备
支持iCloud简记

11 管理资源库
ALAssetsLibrary-代码操作iOS相册资源
ALAssetsLibrary提供了我们对iOS设备中的相片、视频的访问。

可以通过valueForProperty获取到图片的信息,包括类型, Location , 时长,方向,日期,格式 , URL地址。
[cpp] view plaincopyprint?
  1. self.view.backgroundColor = [UIColor whiteColor];  
  2.     self.assetsLibrary = [[ALAssetsLibrary alloc] init];  
  3.     dispatch_queue_t dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);  
  4.     dispatch_async(dispatchQueue, ^(void)  
  5.     {  
  6.         // 遍历所有相册  
  7.         [self.assetsLibrary enumerateGroupsWithTypes:ALAssetsGroupAll  
  8.                                           usingBlock:^(ALAssetsGroup *group, BOOL *stop)  
  9.         {  
  10.               // 遍历每个相册中的项ALAsset  
  11.               [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index,BOOL *stop)  
  12.                {  
  13.                     
  14.                   __block BOOL foundThePhoto = NO;  
  15.                   if (foundThePhoto)  
  16.                   {  
  17.                       *stop = YES;  
  18.                   }  
  19.                   // ALAsset的类型  
  20.                   NSString *assetType = [result valueForProperty:ALAssetPropertyType];  
  21.                    //如果是照片的话  
  22.                    //ALAssetTypeVideo  
  23.                    //ALAssetTypeUnknown  
  24.                   if ([assetType isEqualToString:ALAssetTypePhoto])  
  25.                   {  
  26.                       foundThePhoto = YES;  
  27.                       *stop = YES;  
  28.                       //封装了ALAsset,包含了一个资源文件中的很多属性。(可以说是ALAsset的不同的表示方式,本质上都表示同一个资源文件)  
  29.                       ALAssetRepresentation *assetRepresentation = [result defaultRepresentation];  
  30.                       CGFloat imageScale = [assetRepresentation scale];  
  31.                       UIImageOrientation imageOrientation = (UIImageOrientation)[assetRepresentation orientation];  
  32.                       dispatch_async(dispatch_get_main_queue(), ^(void)  
  33.                       {  
  34.                           CGImageRef imageReference = [assetRepresentation fullResolutionImage];  
  35.                           // 对找到的图片进行操作  
  36.                           UIImage *image = [[UIImage alloc] initWithCGImage:imageReference scale:imageScale orientation:imageOrientation];  
  37.                           if (image != nil)  
  38.                           {  
  39.                               //呈现  
  40.                               self.imageView = [[UIImageView alloc] initWithFrame:self.view.bounds];  
  41.                               self.imageView.contentMode = UIViewContentModeScaleAspectFit;  
  42.                               self.imageView.image = image;  
  43.                               [self.view addSubview:self.imageView];  
  44.                           } else  
  45.                           {  
  46.                               NSLog(@"Failed to create the image.");  
  47.                           }  
  48.                       });  
  49.                   }  
  50.               }];  
  51.           }  
  52.         failureBlock:^(NSError *error)  
  53.         {  
  54.             //读取失败的处理  
  55.         }];  
  56.     });  

12 GLKit
如何为iOS5创建一个简单GLKit应用程序

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

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

参考:http://blog.163.com/const_yixinyiyi/blog/static/180088172201301522234553/
原创粉丝点击