在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("通知完毕")
}
}
网友评论