iOS9的3D Touch

新的触摸体验—— iOS9 3D Touch
 

(iOS9新特性——3Dtouchaa

http://blog.csdn.net/tx874828503/article/details/48786003

)

引言

        iphone6s问世之后,很多果粉都争先要体验3D Touch给用户带来的额外维度上的交互,这个设计之所以叫做3D Touch,其原理上是增加了一个压力的感触,通过区分轻按和重按来进行不同的用户交互。

 

 

UIApplicationShortcutItem 创建3DTouch标签的类

UIMutableApplicationShortcutItem 创建可变的3DTouch标签的类(//这个类继承于 UIApplicationShortcutItem,创建的标签可变  )

 UIApplicationShortcutIcon 创建标签中图片Icon的类(//这个类创建标签中的icon  

@interface UIApplicationShortcutIcon : NSObject <NSCopying>  

//创建系统风格的icon  

+ (instancetype)iconWithType:(UIApplicationShortcutIconType)type;  

//创建自定义的图片icon  

+ (instancetype)iconWithTemplateImageName:(NSString *)templateImageName;  

@end  

)

 

这里,将系统风格icon的枚举列举如下:(9.1后有更多)

 

 

 typedef NS_ENUM(NSInteger, UIApplicationShortcutIconType) {  

     UIApplicationShortcutIconTypeCompose,//编辑的图标  

     UIApplicationShortcutIconTypePlay,//播放图标  

     UIApplicationShortcutIconTypePause,//暂停图标  

     UIApplicationShortcutIconTypeAdd,//添加图标  

     UIApplicationShortcutIconTypeLocation,//定位图标  

     UIApplicationShortcutIconTypeSearch,//搜索图标  

     UIApplicationShortcutIconTypeShare//分享图标  

} NS_ENUM_AVAILABLE_IOS(9_0);  


- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

也需要进行一下判断,在launchOptions中有UIApplicationLaunchOptionsShortcutItemKey这样一个键,通过它,我们可以区别是否是从标签进入的app,如果是则处理结束逻辑后,返回NO,防止处理逻辑被反复回调。 

几点注意:

1、快捷标签最多可以创建四个,包括静态的和动态的。

2、每个标签的题目和icon最多两行,多出的会用...省略

 

 代码:

1.(动态)

 //第二种

    UIMutableApplicationShortcutItem *shortItem1 = [[UIMutableApplicationShortcutItem allocinitWithType@"one"localizedTitle@"one" localizedSubtitle@"one subtitle" icon: [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdduserInfonil];

    NSArray *shortItems = [[NSArray allocinitWithObjects: shortItem1, nil];

    shortItem1.icon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeCaptureVideo];

    [[UIApplication sharedApplicationsetShortcutItems: shortItems];

   

    //第一种

//    UIApplicationShortcutItem *shortItem1 =[[UIApplicationShortcutItem alloc] initWithType:@"斋打开"localizedTitle:@"斋打开"];

//    UIApplicationShortcutItem *shortItem2 =[[UIApplicationShortcutItem alloc] initWithType:@"弹框"localizedTitle:@"弹框"];

//    UIApplicationShortcutItem *shortItem3 =[[UIApplicationShortcutItem alloc] initWithType: @"跳转"localizedTitle: @"gohome" localizedSubtitle: nil icon:[UIApplicationShortcutIcon iconWithType: UIApplicationShortcutIconTypePlay]userInfo: nil];

//    UIApplicationShortcutItem *shortItem4 =[[UIApplicationShortcutItem alloc] initWithType: @"跳转"localizedTitle: @"something" localizedSubtitle: nil icon: [UIApplicationShortcutIconiconWithTemplateImageName: @"login_icon_user_in.png"] userInfo: nil];

//

//    NSArray *shortItems = [[NSArray alloc]initWithObjects:shortItem1, shortItem2, shortItem3, shortItem4, nil];

//   

//    NSLog(@"%@", shortItems);

//    [[UIApplication sharedApplication]setShortcutItems:shortItems];

//   

    //用于开发

//    UIApplicationShortcutItem *item =[launchOptions valueForKey:UIApplicationLaunchOptionsShortcutItemKey];

//    if (item)

//    {

//        NSLog(@"We've launched fromshortcut item: %@", item.localizedTitle);

//    }

//    else

//    {

//        NSLog(@"We've launchedproperly.");

//    }

 

2. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{

    if ([shortcutItem.localizedTitle  isEqual@"弹框"]) {

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"OPPS!" message:@"我的CTO叫佛山强"delegate:self cancelButtonTitle:@"" otherButtonTitles:nil,nil];

        [alert show];

        return;

    }else if ([shortcutItem.localizedTitle isEqual:@"gohome"])

    {

        if (![CommonUtil getObjectFromUD@"UserInfo"]){

           

            LoginViewController *login = [[LoginViewController allocinit];

            [self.navi pushViewController: login animated:NO];

           

        }

       

    }

}
效果图: 

 图片

 参考网址:

 iOS9 3DTouchShortcutItemPeek And Pop技术一览http://blog.csdn.net/showhilllee/article/details/48376073

 

 

iOS 3D Touch (UIApplicationShortcutItemUIViewControllerPreviewingUIPreviewAction)

http://blog.csdn.net/liwenjie0912/article/details/49178873

 

 

接着这里要说的是  长按touchViewController  弹出 自定义的ViewContoller

首先 ViewController.m 里面加入(这个就是要手指 长按并且要往下压的ViewController- (void)viewDidLoad  

{  

    [super viewDidLoad];  

    // Do any additionalsetup after loading the view, typically from a nib.  

      

    //首先要判断一下 压力感是否有效,跟着注册delegate  

    [self check3DTouch];  

}  

  

- (void)check3DTouch  

{  

     

    // register for 3D Touch (if available)  

    if (self.traitCollection.forceTouchCapability == UIForceTouchCapabilityAvailable)  

    {  

        [self registerForPreviewingWithDelegate:self sourceView:self.view];  

        NSLog(@"3D Touch  可用!");  

    }  

    else  

    {  

        NSLog(@"3D Touch 无效");  

    }  

}  

- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location  

{  

    // check if we're not already displaying a preview controller  

    //SecViewController 是要弹出悬浮展示的ViewController  

    if ([self.presentedViewController isKindOfClass:[SecViewController class]]) {  

        return nil

    }  

  

    SecViewController *sec = [[SecViewController alloc] init];  

  

    return sec;  

      

}  

 

未了方便的演示 我们在SecViewController 里面加上一个返回的手势

 

[objc] view plaincopy

 

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dismissMe)];  

             [self.view addGestureRecognizer:tap];  

   

 - (void)dismissMe{  

     // dismiss this view controller  

    [self dismissViewControllerAnimated:YES completion:nil];  

 

当弹出自定义的SecViewController之后 然后我们往上移动那么就会出现Action

这代码是写在SecViewController里面的

 

[objc] view plaincopy

 

 - (NSArray<id<UIPreviewActionItem>> *)previewActionItems {  

       

     // setup a list of preview actions  

     UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"这里可以做你想要做的事情的Aciton" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {  

         NSLog(@"click");  

     }];  

       

     // add them to an arrary  

     //想要显示多个就定义多个 UIPreviewAction 

     NSArray *actions = @[action1];  

       

     // and return them (return the array of actions instead to see all items ungrouped)  

     return actions;  

}  

 

iOS9新特性——3Dtouchaa

http://blog.csdn.net/tx874828503/article/details/48786003

 

享趣客户端有例子

1.       签代理UIViewControllerPreviewingDelegate

2.       注册

-   (void)viewDidLoad

if (self.traitCollection.forceTouchCapability ==UIForceTouchCapabilityAvailable) {

       

       [self registerForPreviewingWithDelegateselfsourceViewself.view];

   }else{

      NSLog(@"3DTouch 无效");

    }

3.       实现代理方法

 

- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location

{

//    if([self.presentedViewController isKindOfClass: [SharedViewController class]]) {

//       

//       return  nil;

//    }

// SharedViewController你想要 弹出的ViewController

    SharedViewController *share = [[SharedViewController allocinit];

   

    return share;

}

//这个方法是在什么时候出发呢?就是 给更加大的力度的时候进去 全屏状  

- (void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {  

      

    // deep press: bring up the commit view controller (pop)  

    [self showViewController:viewControllerToCommit sender:self];  

4. 当弹出自定义的SharedViewController 之后 然后我们往上移动那么就会出现Action

这代码是写在SharedViewController 里面的

 - (NSArray<id<UIPreviewActionItem>> *)previewActionItems {  

     

    // setup a list of preview actions  

    UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"这里可以做你想要做的事情的Aciton" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {  

        NSLog(@"click");  //点击回调方法


    }];  

      

    // add them to an arrary  

    //想要显示多个就定义多个 UIPreviewAction  

    NSArray *actions = @[action1];  

      

    // and return them (return the array of actions instead to see all items ungrouped)  

    return actions;  


效果图:
 
图片

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值