在appDelegate中添加點擊監(jiān)聽,發(fā)送通知即可
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))
{
//發(fā)送通知
//發(fā)通知,監(jiān)聽通知不用我教你了吧,哈哈哈
}
}
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!) {
//發(fā)送通知
print("發(fā)送通知")
NSNotificationCenter.defaultCenter().postNotificationName("StatusBarClickNotification",
object: self, userInfo: nil)
print("通知完畢")
}
}