3DTouch
UITouch类里API的变化
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
动态方式
获取当前应用程序的shortcutItems
id existShortcutItems = [[UIApplication sharedApplication] shortcutItems];
修改当前应用程序的某个shortcutItem
id oldItem = [existingShortcutItems objectAtIndex: 0]; //获取第0个shortcutItem
id mutableItem = [oldItem mutableCopy]; //将oldItem变为可变类型的shortcutItem
[mutableItem setLocalizedTitle: @“Click Lewis”];//修改shortcutItem的标题
重置当前应用程序的shortcutItems
id updatedShortcutItems = [existingShortcutItems mutableCopy]; //生成可变shortcutItems数组
[updatedShortcutItems replaceObjectAtIndex: 0 withObject: mutableItem]; //修改可变shortcutItems数组
[app setShortcutItems: updatedShortcutItems]; //修改应用程序的shortcutItems
创建一个新的UIApplicationShortcutItem
初始化函数
- initWithType:localizedTitle:localizedSubtitle:icon:userInfo:
- initWithType:localizedTitle:
属性
.localizedTitle //标题
.localizedSubtitle //副标题
.type //类型
.icon //图标UIApplicationShortcutIcon
.userInfo
//注意:以上属性都是只读属性,想要进行修改时,需要通过mutableCopy方法转变为NSMutableApplicationShortcutItem
创建一个新的Item图标
初始化函数
+iconWithType:
+ iconWithTemplateImageName:
+ iconWithContact:
当程序启动时
判断launchOptions字典内的UIApplicationLaunchOptionsShortcutItemKey是否为空
当不为空时,application:didFinishLaunchWithOptions方法返回false,否则返回true
在application:performActionForShortcutItem:completionHandler方法内处理点击事件
Peek and Pop
注册预览功能的代理对象和源视图
注册方法声明在UIViewController类内
[self registerForPreviewingWithDelegate:self sourceView:self.view];
代理对象需要接受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
配置previewActionItems
-(NSArray<id<UIPreviewActionItem>> *)previewActionItems
{
//初始化UIPreviewAction
UIPreviewAction * action1 = [UIPreviewAction actionWithTitle:@"选项1" style:0 handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"click");
}];
UIPreviewAction * action2 = [UIPreviewAction actionWithTitle:@"选项2" style:1 handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"click");
}];
UIPreviewAction * action3 = [UIPreviewAction actionWithTitle:@"选项3" style:2 handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
NSLog(@"click");
}];
NSArray * actions = @[action1,action2,action3];
return actions;
}