让非6s的越狱设备支持3DTouch

Posted by leisuro on 2016-06-10

百度百科资料 : 3D Touch的触控技术,被苹果称为新一代多点触控技术。其实,就是此前在Apple Watch上采用的Force Touch,屏幕可感应不同的感压力度触控。

1
3DTouch

这让我们大于9.0系统, 设备又不是6s的人情何以堪. /(ㄒoㄒ)/~~ 我这等穷丝当然也不会为了体验去换一台.

让我们设想一下, 3DTouch是一种多点触控技术, 老版本的iPhone在这方面是没有这个硬件支持的, 那么我们如何去让iPhone也支持这个功能?

原理: 虽然在硬件上不支持手势, 但是Api都在, 我们可以自己新建长按手势, 对每个SBIconView(桌面上的每个View)添加手势, 然后让设备与屏幕假装支持3DTocuh 来蒙骗系统.

换成Tweak代码的话就是:

1.初始化SBIconView添加长按手势

- (id)initWithContentType:(unsigned long long)arg1 {
SBIconController *sbIconC = [objc_getClass("SBIconController") sharedInstance];
UILongPressGestureRecognizer *shortcutMenuPeekGesture = MSHookIvar<UILongPressGestureRecognizer *>(self, "_shortcutMenuPeekGesture");
shortcutMenuPeekGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:sbIconC action:@selector(_handleShortcutMenuPeek:)];
[self addGestureRecognizer:shortcutMenuPeekGesture];
// add swipe-up alternative for those weren't able to get the longpress to edit to work
UISwipeGestureRecognizer *swipeGest = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(revealMenuSwiped:)];
[swipeGest setDirection:4];
[self addGestureRecognizer:swipeGest];
return %orig;
}

- (void)revealMenuSwiped:(id)arg1 {
[self _handleSecondHalfLongPressTimer:nil];
}
- (void)_updateJitter {
// in case any error :)
SBIconController *sbIconC = [objc_getClass("SBIconController") sharedInstance];
[sbIconC _dismissShortcutMenuAnimated:YES completionHandler:^{

}];
}

2.改变UIDevice与UIScreen对force的支持

// add support of Peek and Pop
// something missing here ;)
%hook UIScreen
- (int)_forceTouchCapability {
return 1;
}
%end
%hook UITraitCollection
- (int)forceTouchCapability {
return 1;
}
%end
%hook UIDevice
- (BOOL)_supportsForceTouch {
return YES;
}
- (BOOL)_supportsHapticFeedback {
return YES;
}

核心代码就是这样, 可以看iMokhles完整的Github代码.
https://github.com/iMokhles/RevealMenu

ps:就这样就完成了, 以上只针对越狱过的设备喔.

欢迎交流, 我是leisuro.