iOS开发收集

3DTouch 知识点详解

2016-01-06  本文已影响616人  GoGooGooo

下篇为大家提供一个3DTouch的简单Demo

和开发人员关系比较密切的部分:


下面是在网上搜罗后自己总结的知识点


UITouch类里API的变化

altitudeAngle: 当笔平行于平面时,该值为0 当笔垂直于平面时,该值为Pi / 2
estimatedProperties 当前触摸对象估计的触摸特性 返回值是UITouchPropertyies
updatedProperties 当前触摸对象已经更新的触摸特性 返回值是UITouchPropertyies
estimationUpdateIndex 当每个触摸对象的触摸特性发生变化时,该值将会单独增加
返回值是NSNumber

iOS9中添加的方法
UIForceTouchCapability

UIForceTouchCapabilityUnknown 不能确定是否支持压力感应
UIForceTouchCapabilityUnavailable 不能支持压力感应
UIForceTouchCapabilityAvailable 可以支持压力感应

UITouchType

UITouchTypeDirect 垂直的触摸类型
UITouchTypeIndirect 非初值的触摸类型
UITouchTypeStylus 水平的触摸类型


ShortcutItem



静态方式

动态方式
修改当前应用程序的某个shortcutItem
//获取第0个shortcutItem
  id oldItem = [existingShortcutItems objectAtIndex: 0];  //将旧的shortcutItem改变为可修改类型shortcutItem
  id mutableItem = [oldItem mutableCopy];  //修改shortcutItem的显示标题
  [mutableItem setLocalizedTitle: @“Click Lewis”];

获取当前应用程序的shortcutItems

 //获取当前应用程序对象
  UIApplication *app = [UIApplication sharedApplication];  //获取一个应用程序对象的shortcutItem列表
  id existingShortcutItems = [app shortcutItems];

重置当前应用程序的shortcutItems

//根据旧的shortcutItems生成可变shortcutItems数组
  id updatedShortcutItems = [existingShortcutItems mutableCopy];  //修改可变shortcutItems数组中对应index下的元素为新的shortcutItem
  [updatedShortcutItems replaceObjectAtIndex: 0 withObject: mutableItem];  //修改应用程序对象的shortcutItems为新的数组
  [app setShortcutItems: updatedShortcutItems];

创建一个新的UIApplicationShortcutItem

初始化函数

- initWithType:localizedTitle:localizedSubtitle:icon:userInfo:
- initWithType:localizedTitle:

属性

- localizedTitle:NSString
- localizedSubtitle:NSString
- type:NSString
- icon:UIApplicationShortcutIcon
- userInfo:NSDictionary

创建一个新的Item图标

当程序启动时


Peek and Pop



注册预览功能的代理对象和源视图

代理对象需要接受UIViewControllerPreviewingDelegate协议

  @interface RootVC<UIViewControllerPreviewingDelegate>  {}  @end

代理对象实现协议内的Peek和Pop方法

@implementation RootVC
  - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)context viewControllerForLocation:(CGPoint) point 
  {      
      UIViewController *childVC = [[UIViewController alloc] init];
      childVC.preferredContentSize = CGSizeMake(0.0f,300f);      
      CGRect rect = CGRectMake(10, point.y - 10, self.view.frame.size.width - 20,20);
      context.sourceRect = rect;      
      return childVC;
  }
  - (void)previewContext:(id<UIViewControllerPreviewing>)context commitViewController:(UIViewController*)vc
  {
      [self showViewController:vc sender:self];
  }  
@end

注册方法声明在UIViewController类内

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

Demo下载链接: http://pan.baidu.com/s/1hqKxIx2 密码: kgfp

创建一个新的工程
配置info.plist文件
如下图

在 AppDelegate.h文件里面

#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
    @property (strong, nonatomic) UIWindow *window;
@end

AppDelegate.m文件

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {     
    [UIApplication sharedApplication].applicationIconBadgeNumber=0;    
    return YES;
}
 
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void(^)(BOOL succeeded))completionHandler{    //判断先前我们设置的唯一标识
        if([shortcutItem.type isEqualToString:@"UITouchText.share"]){        
            NSArray *arr = @[@"hello 3D Touch"];
            //设置当前的VC 为rootVC
            UIActivityViewController *vc = [[UIActivityViewController alloc]initWithActivityItems:arr applicationActivities:nil];        
            [self.window.rootViewController presentViewController:vc animated:YES completion:^{
            }];
        } else if ([shortcutItem.type isEqualToString:@"UITouchText.search"]) {
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"好想你" delegate:nil cancelButtonTitle:@"cancle" otherButtonTitles:@"sure", nil];
            [alertView show];
        } else if ([shortcutItem.type isEqualToString:@"UITouchText.look"]) {
            UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:@"温馨提示" delegate:nil cancelButtonTitle:@"cancle" destructiveButtonTitle:@"删除" otherButtonTitles:@"更多", nil];
            [sheet showInView:self.window];
        } else if ([shortcutItem.type isEqualToString:@"UITouchText.compose"]) {        
            NSLog(@"UITouchText.compose");
        }
}
上一篇下一篇

猜你喜欢

热点阅读