我已经使用Theos创建了我的第一个应用程序(简单的重新弹簧),目前它通过点击图标来工作,但我希望重做它没有图标(作为调整)并且当我双击时让手机呼吸在任务栏上。
问题是:如何在状态/任务栏上添加双击手势?
感谢。
答案 0 :(得分:2)
我找到了这段代码,我的theos应用程序中会有什么文件进入?
- (void)viewDidLoad {
[super viewDidLoad];
// required
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
scrollView.delegate = self;
scrollView.contentSize = CGSizeMake(0.0f,1.0f);
[scrollView setContentOffset:CGPointMake(0.0f,1.0f) animated:NO];
// optional
scrollView.scrollsToTop = YES; // default is YES.
[self.view addSubview:scrollView];
}
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView {
NSLog(@"Detect status bar is touched.");
/* Your own code. */
return NO;
}
答案 1 :(得分:1)
有几种方法。您可以使用custom events或在应用委托类like there
中捕获触摸好的,你的答案要简单得多。在此处使用-(BOOL)scrollViewShouldScrollToTop:
方法实现您的任务。
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
tapIndex++; // class member
if(tapIndex==2)
{
[self statusBarDoubleTapped];
tapIndex=0;
}
else
{
NSTimeInterval interval = 1; // one second wait for the second tap
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(interval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if(tapIndex==1) // one second since the only status bar tap
tapIndex=0;
});
}
return NO; // don't scroll to top
}
答案 2 :(得分:0)
这是完整的文件:
#import "RootViewController.h"
@implementation RootViewController
- (void)loadView {
self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
self.view.backgroundColor = [UIColor redColor];
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
{
tapIndex++; // class member
if(tapIndex==2)
{
[self statusBarDoubleTapped];
tapIndex=0;
system("killall -9 SpringBoard");
}
else
{
NSTimeInterval interval = 1; // one second wait for the second tap
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(interval * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if(tapIndex==1) // one second since the only status bar tap
tapIndex=0;
});
}
return NO; // don't scroll to top
}
//- (void)launch { system("killall -9 SpringBoard");
}
@end
答案 3 :(得分:0)
这是我在iOS 11上使用Swift 4所做的。
let statusBarWindow = UIApplication.shared.value(forKey: "statusBarWindow") as! UIWindow
let statusBar = statusBarWindow.subviews.first
let doubleTap = UITapGestureRecognizer(target: self, action: #selector(handle(doubleTapStatusBar:)))
doubleTap.numberOfTapsRequired = 2
statusBar?.addGestureRecognizer(doubleTap)