点击状态栏时添加额外功能

Add extra function when status bar is tapped

我希望在点击状态栏时取消隐藏我的导航栏。目前它只是将我的网络视图滚动到顶部。任何人都知道如何让这个工作? webview仍然可以滚动到顶部,这个功能不需要去掉。

创建一个与您的状态栏尺寸相同的 UIWindow,将 UIButton 添加到 UIWindow,并将其放置在您的状态栏顶部。

import UIKit

class ViewController: UIViewController {

    let statusbarWindow = UIWindow()
    let statusbarButton = UIButton()

    override func viewDidLoad() {
        super.viewDidLoad()
        // Setup UIWindow
        statusbarWindow.frame = CGRectMake(0, 0,
            UIApplication.sharedApplication().statusBarFrame.size.width,
            UIApplication.sharedApplication().statusBarFrame.size.height)
        statusbarWindow.windowLevel = UIWindowLevelStatusBar
        statusbarWindow.makeKeyAndVisible()

        // Setup UIButton
        statusbarButton.frame = CGRectMake(0, 0,
            UIApplication.sharedApplication().statusBarFrame.size.width,
            UIApplication.sharedApplication().statusBarFrame.size.height)
        statusbarButton.backgroundColor = UIColor.clearColor()
        statusbarButton.addTarget(self, action: "statusbarButton:", forControlEvents: UIControlEvents.TouchUpInside)
        statusbarWindow.addSubview(statusbarButton)
    }

    func statusbarButton(sender:UIButton!) {
        // Scroll UIWebView to top
        yourWebView.scrollView.contentOffset = CGPoint(0,0)
        // Unhide nav bar here
    }

Apple 文档UIWindowLevel, makeKeyAndVisible