Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Full Screen iOS Swift

is it possible to switch an app from non full screen to full screen?

enter image description here

I have this switch and I want to make that when turned on the app will hide the status bar, when turned off the app won't hide the status bar

So I've implemented this:

@IBAction func fsChanged(sender: AnyObject) {
    if(fullScreenSwitch.on)
    {
        prefersStatusBarHidden()
        println("FS attivato")
    }
    else {
        prefersStatusBarHidden()
        println("FS disattivato")
    }
}

override func prefersStatusBarHidden() -> Bool {
    if(fullScreenSwitch.on)
    {
        return true
    }
    else {
        return false
    }
}

It does work on the actual segue but not in the whole application! How can I make this for ALL the application??

Thank you!

like image 649
ernestocattaneo Avatar asked Dec 17 '14 09:12

ernestocattaneo


2 Answers

in swift 3, swift 4 you should use it

override open var prefersStatusBarHidden: Bool {
    return true
}

can't assign it like this

self.prefersStatusBarHidden = false

it will give you a error

Error: Cannot assign to property: 'prefersStatusBarHidden' is a get-only property

like image 198
Jian Zhong Avatar answered Oct 17 '22 23:10

Jian Zhong


just use a global variable like statusBarIsHidden to hold your desired state

then in each of your view controllers put in the function:

override func prefersStatusBarHidden () -> Bool {return statusBarIsHidden}

//
//  ViewController_no_status_bar.swift
//  hide the status bar
//
//  Created by Scott Yannitell on 4/30/15.
//  Copyright (c) 2015 ohiovr.com. All rights reserved.
//

import UIKit

var statusBarIsHidden = true
class ViewController_no_status_bar: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    override func prefersStatusBarHidden () -> Bool {return statusBarIsHidden}

}
like image 21
Ohiovr Avatar answered Oct 17 '22 21:10

Ohiovr