The Home screen quick action API is for adding shortcuts to your app icon that anticipate and accelerate a user’s interaction with your app. The UIKit peek and pop API lets you provide easy access, within your app, to additional content while maintaining the user’s context. Use the peek quick actions API to provide a press-enabled replacement to your app’s touch-and-hold actions. The Web view peek and pop API lets you enable system-mediated previews of HTML link destinations. The UITouch force properties let you add customized force-based user interaction to your app.
3d Touch 大概有 3 个应用场景,主屏快速启动,而 UIKit peek and pop 和 Web view peek and pop 可以合并为一个预览的功能, 可以根据 force properties 按压属性值做其它交互上的操作。
The system limits the number quick actions displayed when a user presses a Home screen app icon. Within the limited set of displayed quick action titles, your* static quick actions are shown first, starting at the topmost position in the list. If your static items do not consume the permissible number for display and you have also defined dynamic quick actions using this class, then one or more of your dynamic quick actions is displayed.
结论:
系统会限制 Quick Actions 的显示数量,
在 iOS 9 上最多显示 4 个,有些应用确实可以显示5个。
Quick Actions 截图
预览与弹出窗口(Peek and Pop)
Peek and Pop 让 Google 直接翻译意思是偷看和流行,很明显不是苹果想表达的意思。 Peek 英文解释为 look quickly or furtively 快速偷偷的瞥一眼,大约就是预览的意思,doc 上有的这一句
Optional navigation to the view shown in the preview—known as a pop
大概明白是什么意思了。就像微信中这个这个样子
上面这个效果在未联网状态下不受影响,而
加载的是网络资源,当未联网时,就无法实现预览功能, 属于 Web view peek and pop
// An application-specific string that identifies the type of action to perform. @property (nonatomic, copy, readonly) NSString *type;
// Properties controlling how the item should be displayed on the home screen. @property (nonatomic, copy, readonly) NSString *localizedTitle; @property (nullable, nonatomic, copy, readonly) NSString *localizedSubtitle; @property (nullable, nonatomic, copy, readonly) UIApplicationShortcutIcon *icon;
// Application-specific information needed to perform the action. // Will throw an exception if the NSDictionary is not plist-encodable. @property (nullable, nonatomic, copy, readonly) NSDictionary<NSString *, id <NSSecureCoding>> *userInfo;
// Create an icon using a system-defined image. + (instancetype)iconWithType:(UIApplicationShortcutIconType)type;
// Create an icon from a custom image. // The provided image named will be loaded from the app's bundle // and will be masked to conform to the system-defined icon style. + (instancetype)iconWithTemplateImageName:(NSString *)templateImageName;
@interfaceUIApplication (UIShortcutItems) // Register shortcuts to display on the home screen, or retrieve currently registered shortcuts. @property (nullable, nonatomic, copy) NSArray<UIApplicationShortcutItem *> *shortcutItems NS_AVAILABLE_IOS(9_0) __TVOS_PROHIBITED; @end
// Called when the user activates your application by selecting a shortcut on the home screen, // except when -application:willFinishLaunchingWithOptions: or -application:didFinishLaunchingWithOptions returns NO. - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void(^)(BOOL succeeded))completionHandler NS_AVAILABLE_IOS(9_0) __TVOS_PROHIBITED;
// If you return nil, a preview presentation will not be performed - (nullableUIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location NS_AVAILABLE_IOS(9_0); - (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit NS_AVAILABLE_IOS(9_0);
previewingContext:viewControllerForLocation: Called when the user has pressed a source view in a previewing view controller, thereby obtaining a surrounding blur to indicate that a preview (peek) is available.
previewingContext:commitViewController: Called to let you prepare the presentation of a commit (pop) view from your commit view controller.
这两个方法将会分别在用户按压操作注册了 Peek 的视图对象与 Peek 视图即将从主视图 Pop 时触发。
参数说明
previewingContext The context object for the previewing view controller.
// Registers a view controller to participate with 3D Touch preview (peek) and commit (pop). - (id <UIViewControllerPreviewing>)registerForPreviewingWithDelegate:(id<UIViewControllerPreviewingDelegate>)delegate sourceView:(UIView *)sourceView NS_AVAILABLE_IOS(9_0); - (void)unregisterForPreviewingWithContext:(id <UIViewControllerPreviewing>)previewing NS_AVAILABLE_IOS(9_0);
Swift 的实现风格的可以参考文章后的链接 ViewControllerPreviews: Using the UIViewController previewing APIs。
关于按压属性
1 2 3 4
// Force of the touch, where 1.0 represents the force of an average touch @property(nonatomic,readonly) CGFloat force NS_AVAILABLE_IOS(9_0); // Maximum possible force with this input mechanism @property(nonatomic,readonly) CGFloat maximumPossibleForce NS_AVAILABLE_IOS(9_0);