3D Touch,蘋果iPhone 6s的新功能
有Peek Pop 兩種新手勢
實現(xiàn)點擊app出現(xiàn)小彈框界面的方法
1.在info.plist中進行設(shè)定
2.或者是在appdelegate里面直接進行添加
方法didFinishLaunchingWithOptions中直接添加一下代碼
/**\
UIApplicationShortcutIconTypeCompose,//創(chuàng)作
UIApplicationShortcutIconTypePlay,//播放
UIApplicationShortcutIconTypePause,//暫停
UIApplicationShortcutIconTypeAdd,//添加
UIApplicationShortcutIconTypeLocation,位置
UIApplicationShortcutIconTypeSearch,搜索
UIApplicationShortcutIconTypeShare,分享
*/
//當然也可以自己設(shè)置圖片
//添加快捷啟動
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上進行跳轉(zhuǎn)
DemoViewController *detailVC = [[DemoViewController alloc] init];
//進行不同界面類型的跳轉(zhuǎn)
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里面的按鈕執(zhí)行壓力感應(yīng)菊碟,一定要執(zhí)行這兩個方法
#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];? ? //一定得是在這個方法里面設(shè)置代理? ? detailVC.delegate = self;? ? return detailVC;}- (void)previewingContext:(id)previewingContext commitViewController:(UIViewController *)viewControllerToCommit {
[self tableView:self.tableView didSelectRowAtIndexPath:[self.tableView indexPathForCell:self.touchCell]];
}
比如說點擊完cell出現(xiàn)的下一集界面就是在這里進行設(shè)定的
5.下一級的視圖的刪除功能需要在下一集的界面里面執(zhí)行
- (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地址