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
動態方式
修改當前應用程序的某個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

注冊預覽功能的代理對象和源視圖
代理對象需要接受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];