如何检测 UIStatusBar/iPhone 上的触摸

发布于 2024-08-26 09:10:33 字数 138 浏览 6 评论 0原文

我正在尝试检测 iPhone 的 UIStatusBar 上的任何触摸,但它不起作用。我已经尝试子类化 UIApplicationUIWindow 来访问它,但仍然没有任何结果。

I'm trying to detect any touch on the iPhone's UIStatusBar but its not working. I've tried subclassing UIApplication and UIWindow to access it but still nothing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌伤ぢ 2024-09-02 09:10:33

根据汤姆的回答,我编写了代码。效果很好。

- (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;
}

Based on Tom's answer, I wrote the code. It works well.

- (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;
}
孤城病女 2024-09-02 09:10:33

您的响应者链中需要有一个 UIScrollView,并且它需要有一个委托集。然后,您可以在委托中重写 scrollViewShouldScrollToTop: ,当用户点击状态栏时将调用该委托。如果您不希望将滚动视图滚动回顶部的默认行为,请务必返回NO

You need to have a UIScrollView in your responder chain, and it needs to have a delegate set. You can then override scrollViewShouldScrollToTop: in the delegate, which will be called when the user taps on the status bar. Be sure to return NO if you don't want the default behavior of scrolling the scroll view back to the top.

も星光 2024-09-02 09:10:33

你不能。状态栏由应用程序持有。您只能打开和关闭它。

更重要的是,任何对状态栏的摆弄都可能会让你的应用程序被苹果拒绝,因为它可能会干扰硬件的操作,例如伪装或隐藏低电量。

如果您需要全屏触摸来查看视图,您应该隐藏状态栏。

You can't. The status bar is held by the application. You can only turn it on and off.

More importantly, any fiddling with the status bar is likely to get your app rejected by Apple because it could interfere with the operation of the hardware e.g. disguising or hiding a low battery.

If you need full screen touches for your views you should just hide the status bar.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文