iOS9 3DTouch、ShortcutItem、Peek And Pop技术一览

UITouch类里API的变化

转载地址:http://www.jianshu.com/p/74fe6cbc542b

iOS9中添加的属性

altitudeAngle

当笔平行于平面时,该值为0

当笔垂直于平面时,该值为Pi / 2

estimatedProperties

当前触摸对象估计的触摸特性

返回值是UITouchPropertyies

updatedProperties

当前触摸对象已经更新的触摸特性

返回值是UITouchPropertyies

estimationUpdateIndex

当每个触摸对象的触摸特性发生变化时,该值将会单独增加

返回值是NSNumber

iOS9中添加的方法

PreciseLocationInView:

当前触摸对象的坐标

PrecisePreviousLocationInView:

当前触摸对象的前置坐标

azimuthAngleInview:

沿着x轴正向的方位角

当与x轴正向方向相同时,该值为0

当view参数为nil时,默认为keyWindow

azimuthUnitVectorInView:

当前触摸对象的方向上的单位向量

当view参数为nil时,默认为keyWindow

UIForceTouchCapability

UIForceTouchCapabilityUnknown

不能确定是否支持压力感应

UIForceTouchCapabilityUnavailable

不能支持压力感应

UIForceTouchCapabilityAvailable

可以支持压力感应

UITouchType
UITouchTypeDirect

垂直的触摸类型

UITouchTypeIndirect

非初值的触摸类型

UITouchTypeStylus

水平的触摸类型

UITouchProperties
UITouchPropertyForce

ShortcutItem

静态方式

打开Info.plist文件
在对应UIApplicationShortcutItems关键字下添加item
动态方式

修改当前应用程序的某个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

只有只读特性,想要进行修改时,需要通过mutableCopy方法转变为
NSMutableApplicationShortcutItem
创建一个新的Item图标

初始化函数

+iconWithType:
+iconWithTemplateImageName:
+iconWithContact:

当程序启动时

判断launchOptions字典内的UIApplicationLaunchOptionsShortcutItemKey是否为空
当不为空时,application:didFinishLaunchWithOptions方法返回false,否则返回true
在application:performActionForShortcutItem:completionHandler方法内处理点击事件
Peek and Pop

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];
一个模仿iOS3D Touch效果的库,因为安卓本身不支持3D Touch,所以事件的触发是用长按点击来替代。项目地址:https://github.com/shalskar/PeekAndPop demo地址:https://github.com/shalskar/PeekAndPopDemo 效果图:使用说明:开始这个库托管在 Jitpack.io,所以在根 build.gradle文件中添加:allprojects {     repositories {        ...         maven { url "https://jitpack.io" }     } }然后在application的 build.gradle文件中添加如下依赖:dependencies {     compile 'com.github.shalskar:PeekAndPop:v0.1.1' }基本的使用很简单,只需一个activity实例,一个为 peek and pop准备的布局文件,一个或者多个在长按之后显示的 peek and pop视图。PeekAndPop peekAndPop = new PeekAndPop.Builder(this)                 .peekLayout(R.layout.peek_view)                 .longClickViews(view)                 .build();你可以调用PeekAndPop对象的getPeekView()来得到 peek view ,并使用 findViewById() 来得到 peek layout中的任意视图。View peekView = peekAndPop.getPeekView(); ImageView imageView = peekView.findViewById(R.id.image_view); TextView textView = peekView.findViewById(R.id.text_view);通常你可能还会想在列表中的某个item被点击时显示peek and pop ,为了让peek and pop正常工作,你需要添加这行代码:                .parentViewGroupToDisallowTouchEvents(viewGroup)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值