在程序入口的代理方法里面执行下面代码???
//3D Touch 分为重压和轻压手势, 分别称作POP(第一段重压)和PEEK(第二段重压), 外面的图标只需要POP即可.
//POP手势图标初始化[UIApplication sharedApplication].shortcutItems = array;
点击图标之后会从这个入口进入App:
#pragma mark - 3DTouch触发的方法
-(void)application:(UIApplication *)application performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL))completionHandler
{
//这里可以实现界面跳转等方法
if ([shortcutItem.type isEqualToString:@"item1"]) {
SFSafariViewController *sv = [[SFSafariViewController alloc]initWithURL:[NSURL URLWithString:@"http://weibo.com/p/1005055844400745/home?from=page_100505_profile&wvr=6&mod=data&is_all=1#place"]];
_window.rootViewController = sv;
NSLog(@"按压了第一个标题");
}
else if ([shortcutItem.type isEqualToString:@"item2"])
{
ViewController *vc = [[ViewController alloc]init];
_window.rootViewController = vc;
NSLog(@"按压了第二个标题");
}
}
然后在处理逻辑!!!
PEEK(第二段重压),
//注册代理
[self registerForPreviewingWithDelegate:self sourceView:self.view];
并遵守协议:UIViewControllerPreviewingDelegate
-(void)previewingContext:(id<UIViewControllerPreviewing>)previewingContext commitViewController:(UIViewController *)viewControllerToCommit
{
//固定这么写
[self showViewController:viewControllerToCommit sender:self];
}
-(UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location
{
//location就是重压点坐标,如果按压点在label上执行以下方法
if (location.x > 100 && location.x < 200 && location.y > 100 && location.y < 200) {
SFSafariViewController *mySV = [[SFSafariViewController alloc]initWithURL:[NSURL URLWithString:URL]];
//第一次按压时,弹出的窗口尺寸,再次按压则跳转到mySV
mySV.preferredContentSize = CGSizeMake(0, 400);
previewingContext.sourceRect = _weiboLabel.frame;//设置高亮区域
return mySV;
}
return nil;
}