iOS状态栏点击监听

在appDelegate中添加点击监听,发送通知即可
objective-C:


- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    
    CGPoint touchLocation = [[[event allTouches] anyObject] locationInView:self.window];
    CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
    NSLog(@"location.x = %f,location.y = %f",touchLocation.x,touchLocation.y);
    if (CGRectContainsPoint(statusBarFrame, touchLocation))
    {
       //发送通知
      //发通知,监听通知不用我教你了吧,哈哈哈
    }
}

swift:


override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        
        let location = (touches as NSSet).anyObject()?.locationInView(self.window)
        
        let statusBarFrame = UIApplication.sharedApplication().statusBarFrame
        
        if CGRectContainsPoint(statusBarFrame, location!) {
            
            //发送通知
            print("发送通知")
            NSNotificationCenter.defaultCenter().postNotificationName("StatusBarClickNotification",
                                                                      object: self, userInfo: nil)
            print("通知完毕")

        }
        
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,229评论 4 61
  • 想当初自己年少轻狂,就是因为不想活在为评职称勾心斗角,拿着可怜的工资和一群误人子弟只知争名夺利的同时为伍,在家人...
    毫无章法阅读 342评论 0 0
  • 总会有很多人对我们说过这样一句话,你还是个孩子。是啊,可能在父母、亲人、或者年长我们的朋友眼里,我们还是个为长大成...
    sw沐晨阅读 358评论 0 0
  • 本文通过一个水果篮子的例子,试图帮助读者理解泛型使用中的PECS原则。本文假设读者对泛型以及泛型通配符有基础性的了...
    安静的猫咪先生阅读 6,987评论 4 16