当使用到的视图继承UIScrollView,并且frame为当前视图的bounds, scrollsToTop = true,以上情况下点击状态栏会使得滚动视图回滚到顶部.
在其他情况下又想知道获取当前的点击事件:
private typealias TouchStatusAction = AppDelegate
extension TouchStatusAction {
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
super.touchesEnded(touches, withEvent: event)
let touchLocation = event!.allTouches()?.first!.locationInView(self.window)
let statusBarFrame = UIApplication.sharedApplication().statusBarFrame
if (CGRectContainsPoint(statusBarFrame, touchLocation!))
{
self.statusBarTouchedAction()
}
}
func statusBarTouchedAction() {
NSNotificationCenter.defaultCenter().postNotificationName("statusBarNotification", object: nil)
}
}
在使用的地方监听
NSNotificationCenter.defaultCenter().addObserver(self, selector: "clickAction", name:"statusBarNotification", object: nil)
OK,完成!