iOS 3DTouch
3D Touch,苹果iPhone 6s的新功能
有Peek Pop 两种新手势
实现点击app出现小弹框界面的方法
1.在info.plist中进行设定
2.或者是在appdelegate里面直接进行添加
方法didFinishLaunchingWithOptions中直接添加一下代码
/**\
UIApplicationShortcutIconTypeCompose,//创作
UIApplicationShortcutIconTypePlay,//播放
UIApplicationShortcutIconTypePause,//暂停
UIApplicationShortcutIconTypeAdd,//添加
UIApplicationShortcutIconTypeLocation,位置
UIApplicationShortcutIconTypeSearch,搜索
UIApplicationShortcutIconTypeShare,分享
*/
//当然也可以自己设置图片
//添加快捷启动
UIApplicationShortcutIcon *icon = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeCompose];
UIApplicationShortcutItem *item = [[UIApplicationShortcutItem alloc]initWithType:@"0" localizedTitle:@"1" localizedSubtitle:nil icon:icon userInfo:nil];
UIApplicationShortcutIcon *icon1 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypePlay];
UIApplicationShortcutItem *item1 = [[UIApplicationShortcutItem alloc]initWithType:@"1" localizedTitle:@"2" localizedSubtitle:nil icon:icon1 userInfo:nil];
UIApplicationShortcutIcon *icon2 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypePause];
UIApplicationShortcutItem *item2 = [[UIApplicationShortcutItem alloc]initWithType:@"2" localizedTitle:@"3" localizedSubtitle:nil icon:icon2 userInfo:nil];
UIApplicationShortcutIcon *icon3 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeAdd];
UIApplicationShortcutItem *item3 = [[UIApplicationShortcutItem alloc]initWithType:@"3" localizedTitle:@"3" localizedSubtitle:nil icon:icon3 userInfo:nil];
UIApplicationShortcutIcon *icon4 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeLocation];
UIApplicationShortcutItem *item4 = [[UIApplicationShortcutItem alloc]initWithType:@"4" localizedTitle:@"3" localizedSubtitle:nil icon:icon4 userInfo:nil];
UIApplicationShortcutIcon *icon5 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeSearch];
UIApplicationShortcutItem *item5 = [[UIApplicationShortcutItem alloc]initWithType:@"5" localizedTitle:@"3" localizedSubtitle:nil icon:icon5 userInfo:nil];
UIApplicationShortcutIcon *icon6 = [UIApplicationShortcutIcon iconWithType:UIApplicationShortcutIconTypeShare];
UIApplicationShortcutItem *item6 = [[UIApplicationShortcutItem alloc]initWithType:@"6" localizedTitle:@"3" localizedSubtitle:nil icon:icon6 userInfo:nil];
[[UIApplication sharedApplication] setShortcutItems:@[item4,item5,item6]];
3.点击不同的小图标进行的操作是,此方法也是写在appdelegate里面的
- (void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler {
UINavigationController *nav = (UINavigationController *)self.window.rootViewController;
//也可以直接在当前最外面的Vc上进行跳转
DemoViewController *detailVC = [[DemoViewController alloc] init];
//进行不同界面类型的跳转
switch ([shortcutItem.type integerValue]) {
case 0:
detailVC.titleStr = @"1";
break;
case 1:
detailVC.titleStr = @"2";
break;
case 2:
detailVC.titleStr = @"3";
break;
case 3:
detailVC.titleStr = @"4";
break;
case 4:
detailVC.titleStr = @"5";
break;
case 5:
detailVC.titleStr = @"6";
break;
case 6:
detailVC.titleStr = @"7";
break;
case 7:
detailVC.titleStr = @"8";
break;
default:
break;
}
[nav pushViewController:detailVC animated:YES];
}
4.点击app里面的按钮执行压力感应,一定要执行这两个方法
#pragma mark - UIViewControllerPreviewingDelegate- (UIViewController *)previewingContext:(id)previewingContext viewControllerForLocation:(CGPoint)location { for (UIView *view in self.tableView.subviews) { NSString *class = [NSString stringWithFormat:@"%@",view.class]; if ([class isEqualToString:@"UITableViewWrapperView"]) for (UIView *littleView in view.subviews) { if ([littleView isKindOfClass:[UITableViewCell class]] && CGRectContainsPoint(littleView.frame, location)) { self.touchCell = (UITableViewCell *)littleView; } } } previewingContext.sourceRect = self.touchCell.frame; DemoViewController *detailVC = [[DemoViewController alloc] init]; //一定得是在这个方法里面设置代理 detailVC.delegate = self; return detailVC;}- (void)previewingContext:(id)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
[self tableView:self.tableView didSelectRowAtIndexPath:[self.tableView indexPathForCell:self.touchCell]];
}
比如说点击完cell出现的下一集界面就是在这里进行设定的
5.下一级的视图的删除功能需要在下一集的界面里面执行
- (NSArray> *)previewActionItems {
UIPreviewAction *action1 = [UIPreviewAction actionWithTitle:@"删除" style:UIPreviewActionStyleDefault handler:^(UIPreviewAction * _Nonnull action, UIViewController * _Nonnull previewViewController) {
if ([self.delegate respondsToSelector:@selector(deleteWithIndexPath:)]) {
[self.delegate deleteWithIndexPath:1];
}
}];
NSArray *actions = @[action1];
return actions;
}
具体的操作可以使用通知代理等等进行操作
具体的gitHub地址Demo地址