• iOS8 新特性


    iOS8新特性主要体现在4方面

    1.UIAlertController 对alert&actionSheet的封装

    UIAlertController.h

    提示框按钮的选择

    typedef NS_ENUM(NSInteger, UIAlertActionStyle) {

        UIAlertActionStyleDefault = 0,

        UIAlertActionStyleCancel,

        UIAlertActionStyleDestructive

    } NS_ENUM_AVAILABLE_IOS(8_0);

    提示框的样式

    typedef NS_ENUM(NSInteger, UIAlertControllerStyle) {

        UIAlertControllerStyleActionSheet = 0,

        UIAlertControllerStyleAlert

    } NS_ENUM_AVAILABLE_IOS(8_0);

    NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying>

    创建提示框按钮 

    + (instancetype)actionWithTitle:(NSString *)title style:(UIAlertActionStyle)style handler:(void (^)(UIAlertAction *action))handler;

    @property (nonatomic, readonly) NSString *title;

    @property (nonatomic, readonly) UIAlertActionStyle style;

    @property (nonatomic, getter=isEnabled) BOOL enabled;

    @end

    NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertController : UIViewController

    创建提示框 

    + (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(UIAlertControllerStyle)preferredStyle;

     添加按钮

    - (void)addAction:(UIAlertAction *)action;

    @property (nonatomic, readonly) NSArray *actions;

    添加文本输入框

    - (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler;

    @property (nonatomic, readonly) NSArray *textFields;

    @property (nonatomic, copy) NSString *title;

    @property (nonatomic, copy) NSString *message;

    @property (nonatomic, readonly) UIAlertControllerStyle preferredStyle;

     简单实用示例

    //    1.创建提示框对象,默认是actionSheet效果

        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"注意" message:@"我的呈现方式变了" preferredStyle:UIAlertControllerStyleAlert];

    //    2.创建取消按钮并添加到提示框上

        [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {

            NSLog(@"取消按钮被点击了");

        }]];

    //    3.呈现提示框

        [self presentViewController:alert animated:YES completion:nil];

    2.UIPopoverController的呈现方式改变不必再像之前那样,直接通过present方式呈现

    UIViewController.h

    typedef NS_ENUM(NSInteger, UIModalPresentationStyle) {

            UIModalPresentationFullScreen = 0,

            UIModalPresentationPageSheet NS_ENUM_AVAILABLE_IOS(3_2),

            UIModalPresentationFormSheet NS_ENUM_AVAILABLE_IOS(3_2),

            UIModalPresentationCurrentContext NS_ENUM_AVAILABLE_IOS(3_2),

            UIModalPresentationCustom NS_ENUM_AVAILABLE_IOS(7_0),

            UIModalPresentationOverFullScreen NS_ENUM_AVAILABLE_IOS(8_0),

            UIModalPresentationOverCurrentContext NS_ENUM_AVAILABLE_IOS(8_0),

            UIModalPresentationPopover NS_ENUM_AVAILABLE_IOS(8_0),

            UIModalPresentationNone NS_ENUM_AVAILABLE_IOS(7_0) = -1,         

    };

    @property (nonatomic,readonly) UIPopoverPresentationController *popoverPresentationController NS_AVAILABLE_IOS(8_0);

    使用示例

    //   1.创建内容控制器

        UITableViewController *contentVc = [[UITableViewController alloc] init];

    //   2.1 设置呈现方式

        contentVc.modalPresentationStyle = UIModalPresentationPopover;

    //   2.2设置在导航栏的左边按钮呈现

        contentVc.popoverPresentationController.barButtonItem = self.navigationItem.leftBarButtonItem;

    //    3.呈现

        [self presentViewController:contentVc animated:YES completion:nil];

    以前的方式

     // 1.创建内容控制器

        UITableViewController *contentVc = [[UITableViewController alloc] init];

          // 2.创建popover

        UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:contentVc];

        popover.popoverContentSize = CGSizeMake(100, 100);

           // 3.呈现

        [popover presentPopoverFromBarButtonItem:self.navigationItem.leftBarButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

    3.获取用户授权的用户隐私保护

    地图定位示例

    //导入定位框架

    #import <CoreLocation/CoreLocation.h>

    @interface ViewController ()<CLLocationManagerDelegate>

    //设置定位对象

    @property(nonatomic,strong)CLLocationManager* maneger;

    @end

    @implementation ViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        //    当使用iOS8定位的时候需要请求用户授权,且在info.plist里添加字段NSLocationAlwaysUsageDescription 请求用户授权的描述

        //    iOS7仅仅需要在info.plist里添加字段Privacy - Location Usage Description 请求用户授权的描述

        //    不需要再写下面的代码

        if (IOS8) {

            [self.maneger requestAlwaysAuthorization];//请求用户授权

    }

            //    开启定位

        [self.maneger startUpdatingLocation];

     }

    4.针对屏幕适配应运而生的size classes

     size classes是为了解决storyboard只能订制一种屏幕样式的问题,它不再是具体的尺寸,而是抽象尺寸

    通过宽/高 的compact any regular 组成了九种组合包含了所有苹果设备的尺寸

    详情 :http://www.cnblogs.com/lijianyi/p/4288462.html

  • 相关阅读:
    解决跨操作系统平台JSON中文乱码问题
    httpencode编码
    DELPHI搭建centos开发环境
    cross socket和msgpack的数据序列和还原
    libmidas.so.2
    开发WINDOWS服务程序
    idhttp访问DATASNAP有密码验证的中间件
    接口操作XML
    HttpApplication中的异步线程
    Assembly类
  • 原文地址:https://www.cnblogs.com/lijianyi/p/4294108.html
Copyright © 2020-2023  润新知