隐藏后状态栏仍然显示为黑色
Status bar still shows in black after hide
我的状态栏在按下按钮时消失了,所有的工作都在树上隐藏和取消隐藏,但是当我回到最后一个视图控制器时,白色状态栏隐藏但仍然留下黑色状态栏显示我' m 使用与我在视图中按下的隐藏按钮相同的代码 Will Disappear。
这里是使用的代码:
//按下按钮会隐藏白色状态栏,下面没有黑色状态栏。
@IBAction func onPlayPressed(sender: AnyObject) {
start()
isHidden = !isHidden
UIView.animateWithDuration(0.3) { () -> Void in
self.setNeedsStatusBarAppearanceUpdate()
}
self.navigationController?.hidesBarsOnTap = false
self.navigationController?.setNavigationBarHidden(true, animated: true)
//此部分隐藏了白色状态栏,但在下方留下了黑色状态栏。
override func viewWillDisappear(animated: Bool) {
synth.pause()
vox.pause()
isHidden = true
UIView.animateWithDuration(0.3) { () -> Void in
self.setNeedsStatusBarAppearanceUpdate()
}
self.navigationController?.hidesBarsOnTap = false
self.navigationController?.setNavigationBarHidden(true, animated: true)
任何帮助将不胜感激。
祝一切顺利
托尼·梅里特
一些术语
状态栏:
导航栏:
导航栏和状态栏:
试试我的示例:
ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var hideButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
if (self.navigationController?.navigationBarHidden)! {
hideButton.setTitle("show", forState: .Normal)
}
}
@IBAction func hideNavigationBar(sender: AnyObject) {
self.navigationController?.hidesBarsOnTap = false
self.navigationController?.setNavigationBarHidden(!(self.navigationController?.navigationBarHidden)!, animated: true)
}
@IBAction func goBack(sender: AnyObject) {
self.navigationController?.popViewControllerAnimated(true)
}
}
Main.storyboard
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="T9D-e2-4rQ">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ZDJ-xV-lml">
<objects>
<viewController id="3W3-SS-KDU" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Mxj-5M-2iY"/>
<viewControllerLayoutGuide type="bottom" id="3C4-b8-R1X"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Hr5-jU-7uD">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="DLX-GN-6Nd">
<rect key="frame" x="283" y="285" width="34" height="30"/>
<state key="normal" title="push"/>
<connections>
<segue destination="aX5-Sj-vzs" kind="show" id="5hq-PZ-fji"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="DLX-GN-6Nd" firstAttribute="centerY" secondItem="Hr5-jU-7uD" secondAttribute="centerY" id="hM7-eb-ZcS"/>
<constraint firstItem="DLX-GN-6Nd" firstAttribute="centerX" secondItem="Hr5-jU-7uD" secondAttribute="centerX" id="yTt-om-iNF"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="PzV-EJ-7im"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="GKQ-Ot-Zmx" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="865" y="375"/>
</scene>
<!--View Controller-->
<scene sceneID="dHO-Tf-TVb">
<objects>
<viewController id="aX5-Sj-vzs" customClass="ViewController" customModule="Whosebug_39240675" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="a3I-YL-ZHX"/>
<viewControllerLayoutGuide type="bottom" id="EDl-yb-Y7O"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="dve-Qr-cm1">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="XYd-b4-iN3">
<rect key="frame" x="285" y="285" width="30" height="30"/>
<state key="normal" title="hide">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="hideNavigationBar:" destination="aX5-Sj-vzs" eventType="touchUpInside" id="8OZ-fj-hkz"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="KHT-Tm-0Sw">
<rect key="frame" x="283" y="323" width="34" height="30"/>
<state key="normal" title="back">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="goBack:" destination="aX5-Sj-vzs" eventType="touchUpInside" id="0Gj-6r-RH0"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="XYd-b4-iN3" firstAttribute="centerY" secondItem="dve-Qr-cm1" secondAttribute="centerY" id="4oU-lu-cib"/>
<constraint firstItem="KHT-Tm-0Sw" firstAttribute="centerX" secondItem="XYd-b4-iN3" secondAttribute="centerX" id="DHD-BE-uLP"/>
<constraint firstItem="KHT-Tm-0Sw" firstAttribute="top" secondItem="XYd-b4-iN3" secondAttribute="bottom" constant="8" symbolic="YES" id="Mfb-X2-i3d"/>
<constraint firstItem="XYd-b4-iN3" firstAttribute="centerX" secondItem="dve-Qr-cm1" secondAttribute="centerX" id="UY9-eH-ABh"/>
</constraints>
</view>
<connections>
<outlet property="hideButton" destination="XYd-b4-iN3" id="uLV-9H-ZwF"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="taE-x0-pMJ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1525" y="376"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="g8h-An-4td">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="T9D-e2-4rQ" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="8Zu-zN-61c">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="3W3-SS-KDU" kind="relationship" relationship="rootViewController" id="P8d-UH-2I1"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="8cC-0q-iMj" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>
我的状态栏在按下按钮时消失了,所有的工作都在树上隐藏和取消隐藏,但是当我回到最后一个视图控制器时,白色状态栏隐藏但仍然留下黑色状态栏显示我' m 使用与我在视图中按下的隐藏按钮相同的代码 Will Disappear。
这里是使用的代码:
//按下按钮会隐藏白色状态栏,下面没有黑色状态栏。
@IBAction func onPlayPressed(sender: AnyObject) {
start()
isHidden = !isHidden
UIView.animateWithDuration(0.3) { () -> Void in
self.setNeedsStatusBarAppearanceUpdate()
}
self.navigationController?.hidesBarsOnTap = false
self.navigationController?.setNavigationBarHidden(true, animated: true)
//此部分隐藏了白色状态栏,但在下方留下了黑色状态栏。
override func viewWillDisappear(animated: Bool) {
synth.pause()
vox.pause()
isHidden = true
UIView.animateWithDuration(0.3) { () -> Void in
self.setNeedsStatusBarAppearanceUpdate()
}
self.navigationController?.hidesBarsOnTap = false
self.navigationController?.setNavigationBarHidden(true, animated: true)
任何帮助将不胜感激。
祝一切顺利 托尼·梅里特
一些术语
状态栏:
导航栏:
导航栏和状态栏:
试试我的示例:
ViewController.swift
import UIKit
class ViewController: UIViewController {
@IBOutlet var hideButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
if (self.navigationController?.navigationBarHidden)! {
hideButton.setTitle("show", forState: .Normal)
}
}
@IBAction func hideNavigationBar(sender: AnyObject) {
self.navigationController?.hidesBarsOnTap = false
self.navigationController?.setNavigationBarHidden(!(self.navigationController?.navigationBarHidden)!, animated: true)
}
@IBAction func goBack(sender: AnyObject) {
self.navigationController?.popViewControllerAnimated(true)
}
}
Main.storyboard
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="T9D-e2-4rQ">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="ZDJ-xV-lml">
<objects>
<viewController id="3W3-SS-KDU" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="Mxj-5M-2iY"/>
<viewControllerLayoutGuide type="bottom" id="3C4-b8-R1X"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="Hr5-jU-7uD">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="DLX-GN-6Nd">
<rect key="frame" x="283" y="285" width="34" height="30"/>
<state key="normal" title="push"/>
<connections>
<segue destination="aX5-Sj-vzs" kind="show" id="5hq-PZ-fji"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="DLX-GN-6Nd" firstAttribute="centerY" secondItem="Hr5-jU-7uD" secondAttribute="centerY" id="hM7-eb-ZcS"/>
<constraint firstItem="DLX-GN-6Nd" firstAttribute="centerX" secondItem="Hr5-jU-7uD" secondAttribute="centerX" id="yTt-om-iNF"/>
</constraints>
</view>
<navigationItem key="navigationItem" id="PzV-EJ-7im"/>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="GKQ-Ot-Zmx" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="865" y="375"/>
</scene>
<!--View Controller-->
<scene sceneID="dHO-Tf-TVb">
<objects>
<viewController id="aX5-Sj-vzs" customClass="ViewController" customModule="Whosebug_39240675" customModuleProvider="target" sceneMemberID="viewController">
<layoutGuides>
<viewControllerLayoutGuide type="top" id="a3I-YL-ZHX"/>
<viewControllerLayoutGuide type="bottom" id="EDl-yb-Y7O"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="dve-Qr-cm1">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="XYd-b4-iN3">
<rect key="frame" x="285" y="285" width="30" height="30"/>
<state key="normal" title="hide">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="hideNavigationBar:" destination="aX5-Sj-vzs" eventType="touchUpInside" id="8OZ-fj-hkz"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="KHT-Tm-0Sw">
<rect key="frame" x="283" y="323" width="34" height="30"/>
<state key="normal" title="back">
<color key="titleColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</state>
<connections>
<action selector="goBack:" destination="aX5-Sj-vzs" eventType="touchUpInside" id="0Gj-6r-RH0"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstItem="XYd-b4-iN3" firstAttribute="centerY" secondItem="dve-Qr-cm1" secondAttribute="centerY" id="4oU-lu-cib"/>
<constraint firstItem="KHT-Tm-0Sw" firstAttribute="centerX" secondItem="XYd-b4-iN3" secondAttribute="centerX" id="DHD-BE-uLP"/>
<constraint firstItem="KHT-Tm-0Sw" firstAttribute="top" secondItem="XYd-b4-iN3" secondAttribute="bottom" constant="8" symbolic="YES" id="Mfb-X2-i3d"/>
<constraint firstItem="XYd-b4-iN3" firstAttribute="centerX" secondItem="dve-Qr-cm1" secondAttribute="centerX" id="UY9-eH-ABh"/>
</constraints>
</view>
<connections>
<outlet property="hideButton" destination="XYd-b4-iN3" id="uLV-9H-ZwF"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="taE-x0-pMJ" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1525" y="376"/>
</scene>
<!--Navigation Controller-->
<scene sceneID="g8h-An-4td">
<objects>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="T9D-e2-4rQ" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="8Zu-zN-61c">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="3W3-SS-KDU" kind="relationship" relationship="rootViewController" id="P8d-UH-2I1"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="8cC-0q-iMj" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="53" y="375"/>
</scene>
</scenes>
</document>