你好,欢迎来到电脑编程技巧与维护杂志社! 杂志社简介广告服务读者反馈编程社区  
合订本订阅
 
 
您的位置:技术专栏 / 数据库开发
IOS 5新增API介绍及使用
 

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)- 框架详解

 

  推荐精品文章

·2024年12月目录 
·2024年11月目录 
·2024年10月目录 
·2024年9月目录 
·2024年8月目录 
·2024年7月目录 
·2024年6月目录 
·2024年5月目录 
·2024年4月目录 
·2024年3月目录 
·2024年2月目录 
·2024年1月目录
·2023年12月目录
·2023年11月目录

  联系方式
TEL:010-82561037
Fax: 010-82561614
QQ: 100164630
Mail:gaojian@comprg.com.cn

  友情链接
 
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved
京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089