標籤:
[iOS]iOS9 3DTouch、ShortcutItem、Peek And Pop技術一覽 3DTouchUITouch類裡API的變化iOS9中添加的屬性
altitudeAngle
當筆平行於平面時,該值為0
當筆垂直於平面時,該值為Pi / 2
estimatedProperties
當前觸摸對象估計的觸摸特性
傳回值是UITouchPropertyies
updatedProperties
當前觸摸對象已經更新的觸摸特性
傳回值是UITouchPropertyies
estimationUpdateIndex
iOS9中添加的方法
- PreciseLocationInView:
- PrecisePreviousLocationInView:
- azimuthAngleInview:
- azimuthUnitVectorInView:
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:
屬性
建立一個新的Item表徵圖
當程式啟動時
- 判斷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];
iOS9 3DTouch、ShortcutItem、Peek And Pop技術一覽