2016-10-19 1 views
0

enter image description hereWie stelle ich die Statusleiste in iOS so ein, dass eine Nachricht angezeigt wird?

Ich suche eine Nachricht direkt unterhalb der Statusleiste zu setzen, und möglicherweise die Farbe der Mitteilung ändern (siehe Foto - freue dich auf eine Nachricht zu setzen, wo „Schlaf-Zyklus“ ist).

Ich habe jedoch die Human Design Guidelines von iOS angeschaut, kann aber nicht feststellen, wie dieses Steuerelement heißt.

https://developer.apple.com/ios/human-interface-guidelines/ui-bars/navigation-bars/

Nur ein Punkt in die richtige Richtung wird eine große Hilfe sein.

+0

ist es ähnlich [this] (https://github.com/bryxinc/BRYXBanner)? –

+0

Nein :) Diese "Statusleiste Nachricht" existiert außerhalb der App. Das scheint In-App zu sein. – kev

+0

Sie können das nicht von außerhalb Ihrer App tun, es sei denn, Sie verwenden einen Hintergrunddienst wie Audioaufnahme. Und das System zeigt es auch, Sie haben keine Kontrolle darüber – Sandeep

Antwort

3

Versuchen Sie diesen Code: Code in Xcode getestet 8.

/Aktualisieren Sie Ihren plist mit folgendem Code

View controller-based status bar appearance = NO 

// In Ihrem VC:

 override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    title = "Some Title" 

    navigationController?.navigationBar.tintColor = UIColor.white 
    navigationController?.navigationBar.barTintColor = UIColor.red 
    navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white] 
    UIApplication.shared.statusBarStyle = .lightContent // To change your status bar to display light content (In white colour) 
    } 

    func sleepCycleNotify() { 

    // To set BannerView 
    let barView = UIView(frame: CGRect(x:0, y:0, width:view.frame.width, height:(UINavigationController().navigationBar.frame.height))) 
    barView.backgroundColor=UIColor.red // set to any colour you want.. 
    navigationController?.navigationBar.addSubview(barView) 

    let notifyLabel = UILabel() 
    notifyLabel.frame = CGRect(x:0, y:0, width:view.frame.width, height:(UINavigationController().navigationBar.frame.height)) 
    notifyLabel.backgroundColor=UIColor.clear 
    notifyLabel.text = "Sleep Cycle" 
    notifyLabel.textAlignment = .center 
    notifyLabel.textColor = UIColor.white 
    notifyLabel.alpha = 0.8 
    barView.addSubview(notifyLabel) 


    // Animation 1: 
    // To achive animation 
    barView.center.y -= (navigationController?.navigationBar.bounds.height)! 


    UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.6, options: UIViewAnimationOptions.curveEaseIn, animations:{ 
     barView.center.y += (self.navigationController?.navigationBar.frame.height)! 


     }, completion:{ finished in 



      UIView.animate(withDuration: 1, delay: 1.5, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.9, options: UIViewAnimationOptions.curveEaseOut, animations:{ 

       barView.center.y -= ((self.navigationController?.navigationBar.frame.height)! + UIApplication.shared.statusBarFrame.height) 

       }, completion: nil) 

    }) 


} 

Ausgabe von oben Code:

enter image description here

// Animation, 2:

func sleepCycleNotify() { 

    // 
    let barView = UIView(frame: CGRect(x:0, y:0, width:view.frame.width, height:(UINavigationController().navigationBar.frame.height))) 
    barView.backgroundColor=UIColor.red // set any colour you want.. 
    navigationController?.navigationBar.addSubview(barView) 

    let notifyLabel = UILabel() 
    notifyLabel.frame = CGRect(x:0, y:0, width:view.frame.width, height:(UINavigationController().navigationBar.frame.height)) 
    notifyLabel.backgroundColor=UIColor.clear 
    notifyLabel.text = "Sleep Cycle" 
    notifyLabel.textAlignment = .center 
    notifyLabel.textColor = UIColor.white 
    notifyLabel.alpha = 0.8 
    barView.addSubview(notifyLabel) 



    // To achive animation 
    barView.center.y -= (navigationController?.navigationBar.bounds.height)! 


    UIView.animate(withDuration: 1, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.6, options: UIViewAnimationOptions.curveEaseIn, animations:{ 

     UIApplication.shared.isStatusBarHidden = true 
     UINavigationController().navigationBar.isHidden = true 
     barView.center.y += (self.navigationController?.navigationBar.frame.height)! 




     }, completion:{ finished in 



      UIView.animate(withDuration: 1.5, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.9, options: UIViewAnimationOptions.curveEaseOut, animations:{ 
       // notifyLabel.alpha = 0...1 
       UIApplication.shared.isStatusBarHidden = false 
       UINavigationController().navigationBar.isHidden = false 
       barView.center.y -= ((self.navigationController?.navigationBar.frame.height)! + UIApplication.shared.statusBarFrame.height) 


       }, completion: nil) 

    }) 


} 

Ausgabe von Animation 2:

enter image description here

Verbesserte Antwort:

override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    title = "Some Title" 

    navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName:UIColor.white] 
    navigationController?.navigationBar.barTintColor = UIColor.purple 
    UIApplication.shared.statusBarStyle = .lightContent 

    } 

    func sleepCycleNotify() { 

    // To set BannerView 
    let barView = UIView(frame: CGRect(x:0, y:-UIApplication.shared.statusBarFrame.height, width:view.frame.width, height:(UINavigationController().navigationBar.frame.height) + UIApplication.shared.statusBarFrame.height)) 
    barView.backgroundColor=UIColor.red // set to any colour you want.. 
    navigationController?.navigationBar.addSubview(barView) 


    let notifyLabel = UILabel() 
    notifyLabel.frame = CGRect(x:0, y:UIApplication.shared.statusBarFrame.height, width:view.frame.width, height:(UINavigationController().navigationBar.frame.height)) 
    notifyLabel.backgroundColor=UIColor.clear 
    notifyLabel.numberOfLines = 0 
    notifyLabel.text = "Sleep Cycle" 
    notifyLabel.textAlignment = .center 
    notifyLabel.textColor = UIColor.white 
    notifyLabel.alpha = 0.8 
    barView.addSubview(notifyLabel) 


    // Animation 1: 
    // To achive animation 
    barView.center.y -= (navigationController?.navigationBar.bounds.height)! 


    UIView.animate(withDuration: 0.7, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.6, options: UIViewAnimationOptions.curveEaseIn, animations:{ 
     barView.center.y += (self.navigationController?.navigationBar.frame.height)! 



     }, completion:{ finished in 



      UIView.animate(withDuration: 1, delay: 1.5, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.9, options: UIViewAnimationOptions.curveEaseOut, animations:{ 

       barView.center.y -= ((self.navigationController?.navigationBar.frame.height)! + UIApplication.shared.statusBarFrame.height) 

       }, completion: nil) 

    }) 
} 

Ausgabe von Animation, 3:

enter image description here

Verwandte Themen