【问题标题】:Add extra function when status bar is tapped点击状态栏时添加额外功能
【发布时间】:2015-08-18 12:00:17
【问题描述】:

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

【问题讨论】:

  • 在状态栏上覆盖UIButton
  • 目前还不清楚它与哪个工具相关。您能否提供信息您的意思是什么工具并提供屏幕快照?
  • @DanielStorm 这行不通,因为我有一个由导航控制器定义的导航栏。我无法在状态栏上放置一个按钮 :( 除非我不知道怎么做,如果你能解释一下 :)
  • @kazik1616 Apple 提供了一个让我的 webview 滚动到顶部的功能,我希望它也能显示我之前隐藏的导航栏

标签: ios swift statusbar


【解决方案1】:

创建一个与状态栏尺寸相同的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 文档UIWindowLevelmakeKeyAndVisible

【讨论】:

    猜你喜欢
    • 2020-03-19
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-31
    • 2011-02-21
    • 2014-11-15
    相关资源
    最近更新 更多