2016-08-31 155 views
0

我的狀態欄在按鈕按下時消失,所有工作都隱藏並隱藏在樹上,但是當我回到最後一個視圖控制器時,白色狀態欄隱藏但仍然留下黑色狀態欄顯示我使用的按鈕上使用相同的代碼按下隱藏,因爲我在視圖中將消失。隱藏後狀態欄仍然顯示爲黑色

這裏使用的代碼:

//按下一個按鈕上隱藏的白色狀態欄下面有沒有黑色的狀態欄的作品。

@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) 

任何幫助將不勝感激。

所有最優秀的 託尼·梅里特

回答

0

一些術語

狀態欄:

enter image description here

導航欄:

enter image description here

導航欄和狀態欄:

enter image description here

試試我的樣品:

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="stackoverflow_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> 
+0

嗨瓦西里,感謝您的回覆。對不起,當我說狀態欄時,我並不清楚,我的意思是電池和運營商徽標。當我將酒吧留在那裏時,我只是用黑色而不是白色,當我按下我的播放按鈕時,他們消失了,沒有任何跟蹤,只是無法理解爲什麼它在一個按鈕上播放,而不是視圖消失。我已經解決了這個問題,只需在控制器之間留下整個導航欄和狀態欄,狀態欄上的標誌就會消失。再次感謝您的時間,我會試試看看它是否適用於我。所有的bset –

+0

一切都很好。我很樂意幫助你。那麼,你想在viewDidAppear函數中隱藏導航欄嗎? –

+0

你有沒有找到解決你的問題? –