0

I want to cover the statusbar with a view like the following code shows. I have read a lot that this needs to be done in an separate(?) window that is on the same windows layer as the statusbar but I just don't get it to work.

I tried this (first code) Display UIView Above Apple Status Bar in iOS 8

but my self.view.window? is nil

Trying to create a new UIWindow XCODE wants a rootViewController which I would have to fake... IMHO That cannot be the right way

Here is my code:

class GroupSelectionTVC: UITableViewController {

override func viewDidLoad()
{

    // Toast

    let frame = CGRectMake(0, -20, self.view.frame.width, 20)
    let message = UILabel(frame: frame)
    message.backgroundColor = UIColor.blackColor()
    message.text = "Testing"
    message.textAlignment = NSTextAlignment.Center
    message.textColor = UIColor.darkGrayColor()

    self.view.addSubview(message)

    UIView.animateWithDuration(1.0, animations: {

        message.frame = CGRectMake(0, 0, self.view.frame.width, 20)}, completion:
        {
        (value: Bool) in UIView.animateWithDuration(1.0, delay: 2.0, options: nil, animations: {message.frame = CGRectMake(0, -20, self.view.frame.width, 20)}, completion:
            {
                (value: Bool) in  message.removeFromSuperview()
            }
            )
    }
    )
Community
  • 1
  • 1
Timm Kent
  • 1,123
  • 11
  • 25

1 Answers1

1

I would recommend you to use CRToast. It's a framework for exactly your kind of problem. So you don't have to worry about UIViews etc. It's written in Objective-C but you can easily use it in a Swift project.

Christian
  • 22,585
  • 9
  • 80
  • 106
  • I like this framework. But I would like to understand it and I don't like Objective C in my swift code :-( – Timm Kent Jan 25 '15 at 21:05
  • I implemented it into my code. It REALLY is quite simple. – Timm Kent Jan 27 '15 at 18:14
  • Nice to hear that you like it. The simplicity is also something I like most about that framework. And because Swift is such a new language, there aren't many frameworks for Swift. – Christian Jan 27 '15 at 18:25
  • Is there a reason they don't use the storyboard to setup the demo-environment? It seems to me quite overload to do all the swipe recognition and stuff programmatically. – Timm Kent Jan 28 '15 at 07:16
  • That way, it's much easier to implement in my opinion. Also many people don't use the Storyboard at all. – Christian Jan 28 '15 at 07:21