标签:
1、Home Screen Quick Actions
效果如下:
实现方法一:(用代码写)
在AppDelegate.m 的 application: didFinishLaunchingWithOptions:方法中创建快捷item,
1 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 2 // Override point for customization after application launch. 3 4 // 创建只有标题的item 5 UIApplicationShortcutItem *item1 = [[UIApplicationShortcutItem alloc] initWithType:@"type1" localizedTitle:@"标题1"]; 6 // 创建有标题,且有副标题的item 7 UIApplicationShortcutItem *item2 = [[UIApplicationShortcutItem alloc] initWithType:@"type2" localizedTitle:@"标题2" localizedSubtitle:@"副标题" icon:nil userInfo:nil]; 8 9 // 获取icon对象(系统样式icon) 10 UIApplicationShortcutIcon *icon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeHome]; 11 // 创建有标题,有副标题,有图片(系统)的item 12 UIApplicationShortcutItem *item3 = [[UIApplicationShortcutItem alloc] initWithType:@"type3" localizedTitle:@"标题3" localizedSubtitle:@"系统图标" icon:icon userInfo:nil]; 13 14 UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithTemplateImageName:@"feiji"]; 15 // 有标题,有副标题,有图片(自定义)的item 16 UIApplicationShortcutItem *item4 = [[UIApplicationShortcutItem alloc] initWithType:@"type4" localizedTitle:@"标题4" localizedSubtitle:@"自定义icon" icon:icon2 userInfo:nil];
19 // 添加到icon快捷方式 20 [UIApplication sharedApplication].shortcutItems = @[item1,item2,item3,item4]; 24 return YES; 25 }
实现方法二(修改info.plist)
1 <key>UIApplicationShortcutItems</key> 2 <array> 3 <dict> 4 <key>UIApplicationShortcutItemType</key> 5 <string>title_one</string> 6 <key>UIApplicationShortcutItemTitle</key> 7 <string>标题1</string> 8 <key>UIApplicationShortcutItemSubtitle</key> 9 <string>副标题1</string> 10 </dict> 11 <dict> 12 <key>UIApplicationShortcutItemType</key> 13 <string>title_one</string> 14 <key>UIApplicationShortcutItemTitle</key> 15 <string>标题2</string> 16 <key>UIApplicationShortcutItemSubtitle</key> 17 <string>副标题2</string> 18 <key>UIApplicationShortcutItemIconType</key> 19 <string>UIApplicationShortcutIconTypeLove</string> 20 </dict> 21 <dict> 22 <key>UIApplicationShortcutItemType</key> 23 <string>title_one</string> 24 <key>UIApplicationShortcutItemTitle</key> 25 <string>标题3</string> 26 <key>UIApplicationShortcutItemSubtitle</key> 27 <string>副标题3</string> 28 <key>UIApplicationShortcutItemIconType</key> 29 <string>UIApplicationShortcutIconTypeLove</string> 30 <key>UIApplicationShortcutItemIconFile</key> 31 <string>feiji</string> 32 </dict> 33 </array>
点击某一个item时会调用
application:performActionForShortcutItem:completionHandler:
在在AppDelegate.m中,重写此方法。
1 // 点击某一个item时调用 2 - (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler{ 3 4 // 根据shortcutItem.type 判断点击了哪一个item 5 if ([shortcutItem.type isEqualToString:@"type1"]) { 6 // 做相应 操作 8 }else if ([shortcutItem.type isEqualToString:@"type2"]){10 } 11 }
2、peek and pop
这个功能是一套全新的用户交互机制,在使用3D Touch时,ViewController中会有如下三个交互阶段:
(1)提示用户这里有3D Touch的交互,会使交互控件周围模糊
(2)继续深按,会出现预览视图
(3)通过视图上的交互控件进行进一步交互
这个模块的设计可以在网址连接上进行网页的预览交互。
实现协议 UIViewControllerPreviewingDelegate
实现方法
1 #pragma mark - UIViewControllerPreviewingDelegate 2 3 // peek 4 - (nullable UIViewController *)previewingContext:(id <UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{ 5 6 7 // 转换坐标 8 location = [self.tableView convertPoint:location fromView:[previewingContext sourceView]]; 9 10 // 根据location获取位置 11 NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location]; 12 13 // 创建控制器 14 ViewController *vc = [[ViewController alloc] init]; 15 16 return vc; 17 18 } 19 20 // pop 21 - (void)previewingContext:(id <UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit{ 22 23 // push peek 所看到的UIViewController 24 [self.navigationController pushViewController:viewControllerToCommit animated:YES]; 25 26 }
注意,使用tableView实现peek和pop,需要在返回cell前这样写(调用registerForPreviewingWithDelegate:sourceView:方法)
// 告诉系统每一个cell都可以被peek
[self registerForPreviewingWithDelegate:self sourceView:cell];
这个效果的实现,在peek返回的 UIViewController 中重写 -previewActionItems 方法
- (NSArray<id<UIPreviewActionItem>> *)previewActionItems{ // 创建赞操作 UIPreviewAction *item1 = [UIPreviewAction actionWithTitle:@"赞" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { NSLog(@"赞了%@",self.httpUrl); }]; UIPreviewAction *item2 = [UIPreviewAction actionWithTitle:@"评论" style:UIPreviewActionStyleSelected handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { NSLog(@"评论了%@",self.httpUrl); }]; UIPreviewAction *item3 = [UIPreviewAction actionWithTitle:@"item3" style:UIPreviewActionStyleDestructive handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) { NSLog(@"item3"); }]; // 创建一个组包涵赞和评论 UIPreviewActionGroup *group = [UIPreviewActionGroup actionGroupWithTitle:@"组" style:UIPreviewActionStyleDefault actions:@[item1,item2]]; return @[group,item3]; }
3、Force Properties
iOS9为我们提供了一个新的交互参数:力度。我们可以检测某一交互的力度值,来做相应的交互处理。例如,我们可以通过力度来控制快进的快慢,音量增加的快慢等。
当用力按压屏幕时会调用(即使,手指不滑动) -touchesMoved:withEvent: 方法
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ // 获取触摸对象 UITouch *t = touches.anyObject; t.force // 返回按压力度值(float),实测最大值为6.6666666,最小应该是0. }
标签:
原文地址:http://www.cnblogs.com/kinghx/p/5185239.html