Double tap gesture on status bar

1.3k views Asked by At

I have made my very first app (simple re-spring) with Theos, currently it works by tapping in the icon but I wish to redo it without an icon (as a tweak) and have the phone respiring when I double tap on the task bar.

Question is: how do I add a double tap gesture on the status/task bar?

Thanks.

4

There are 4 answers

4
Daniyar On BEST ANSWER

There're several ways. You can use custom events or capture touches in your app delegate class like there

Ok, your answer is much simpler. To be useful here the -(BOOL)scrollViewShouldScrollToTop: method implementation for your task.

- (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
}
3
Nicoll On

I found this code, what file in my theos app would this go into?

- (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;
}
0
Nicoll On

This is complete file:

#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
0
BumMo Koo On

Here's what I did on iOS 11 using 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)