Hide home button on iPhone X - ios

I have to figure out a way to hide the home button for all of my View controllers in the app.
Yes
override var prefersHomeIndicatorAutoHidden: Bool {
return true
}
is an option but what if I have like 100 VCs, is this the only way?
I use navigation controller so I tried to override this property there, but it doesn't seems to have a reflection on the others as well.
Any ideas? Thanks in advance.

Related

Hiding everything in the iOS navbar, including icons

I've managed to hide the navbar itself, but I want it all gone - charge icon, connection bars, clock - absolutely everything.
I'm aware this may create a 'dead end' for my app, but that's ok for my purposes.
I read here that it's apparently not legal. Is that still true?
The app is not for distribution, so I'd still be interested to hear solutions even if Apple doesn't like it.
Thank you.
I assume you want to hide status bar.
You can use prefersStatusBarHidden property to hide status bar in Swift 4.2:
class ViewController: UIViewController {
override var prefersStatusBarHidden: Bool {
return hideStatusBar
}
override func viewDidLoad() {
super.viewDidLoad()
}
}

Apple TV force focus another view

I'm working on Apple TV project. The project contains tab bar view controller, normally the tab bar will be appeared when swiping up on remote and hidden when swiping down. But now I reverse that behavior and I want to force focus another view when swiping up(normally focus on tab bar). Any way to do that? Thank you.
In your UIViewController, override shouldUpdateFocusInContext. If you detect an upward navigation into the tab bar, return false to prevent focus from reaching the tab bar. Then use a combination of preferredFocusEnvironments + setNeedsFocusUpdate to redirect focus somewhere else:
override func shouldUpdateFocus(in context: UIFocusUpdateContext) -> Bool {
if let nextView: UIView = context.nextFocusedView{
if ( context.focusHeading == .up && nextView.isDescendant(of: tabBar) ){
changeFocusTo(myView)
return false
}
}
}
internal var viewToFocus: UIView?
func changeFocusTo(_ view:UIView? ){
viewToFocus = view
setNeedsFocusUpdate()
}
override var preferredFocusEnvironments: [UIFocusEnvironment]{
return viewToFocus != nil ? [viewToFocus!] : super.preferredFocusEnvironments
}
This is a generally useful technique for customizing focus updates. An alternative technique is to use UIFocusGuide. You could insert a focus guide underneath the tab bar or surround the tab bar with a focus guide to redirect focus. Though focus guides are useful for simple cases, I have generally had better results using the technique I am describing instead.
I got the same issue with focus of UITabbarController before and I found the solution in Apple Support
Because UIViewController conforms to UIFocusEnvironment, custom view
controllers in your app can override UIFocusEnvironment delegate
methods to achieve custom focus behaviors. Custom view controllers
can:
Override the preferredFocusedView to specify where focus should start
by default. Override shouldUpdateFocusInContext: to define where focus
is allowed to move. Override
didUpdateFocusInContext:withAnimationCoordinator: to respond to focus
updates when they occur and update your app’s internal state. Your
view controllers can also request that the focus engine reset focus to
the current preferredFocusedView by callingsetNeedsFocusUpdate. Note
that calling setNeedsFocusUpdate only has an effect if the view
controller contains the currently focused view.
For more detail, please check this link
https://developer.apple.com/library/content/documentation/General/Conceptual/AppleTV_PG/WorkingwiththeAppleTVRemote.html#//apple_ref/doc/uid/TP40015241-CH5-SW14

Prevent UISearchBarController to show UINavigationBar

I'm using a UINavigationBar ALWAYS hidden (I'm using NavigationBar facilities to push ou pop views but I'm not showing it to final user), the problem is that in one of those views I have a tableView with UISearchBar. When I select the searchBar, make a search and click on it's "Cancel" button the NavigationBar appears, but I want to keep the Navigation hidden as it is.
I've tried to hidden the navigationBar one more time by willDismissSearchController or didDismissSearchController by
func willDismissSearchController(searchController: UISearchController) {
self.navigationController?.navigationBar.hidden = true
}
but it did not worked as I want.
Thank you in advance.
I've found a solution, so as it is a unusual question I'll reply for other people know the solution.
the following code did worked for me:
override func viewDidLayoutSubviews() {
self.navigationController?.navigationBar.hidden = true
}

Enable and disable auto rotate programmatically using Swift?

I would like to programmatically disable or enable the auto rotate function using a button using Swift. I was thinking that it might be able to somehow be done using the supportedInterfaceOrientations() function, but I am very confused after looking through the literature about how this is done. Is there an easy solution for this?
You could create an action for the button that sets a boolean flag somewhere in your code and return the value of that flag in the shouldAutorotate method of the view controller. If you need that for all view controllers you could create a common base view controller (inheritance).
Example of button action:
#IBAction func toggleRotation(sender: Button) {
// A made up AppConfig class with class method for setting and retrieving
// rotation flag.
AppConfig.allowRotation(!AppConfig.allowRotation)
}
Example of shouldAutorotate:
override func shouldAutorotate() -> Bool {
return AppConfig.allowRotation()
}
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/#//apple_ref/occ/instm/UIViewController/shouldAutorotate

Swift Orientation override for a viewcontroller

I'm having trouble to allow only 1 view controller in marking portrait,Landscape right and left, that view controller has a button to a video on youtube embed link I just want to allow rotation to this view,
I allowed all orientations in app and tried to add this to other view controllers that I wanted to be portrait but no chance
override func supportedInterfaceOrientations() -> Int {
return UIInterfaceOrientationMask.Portrait.rawValue.hashValue | UIInterfaceOrientationMask.PortraitUpsideDown.rawValue.hashValue
}
is there anyother way to implement this I mean I will only allow portrait in general app setting but override one that in the video view controller view,or just like first one I tried in general setting allow all orientations but allow only portrait in all views except videocontrollerview, thanks advance for any help..
Since there is no code I can't say for sure but you might be missing this in your view controller so that those supportedInterfaceOrientations can work:
override func shouldAutorotate() -> Bool {
return true
}

Resources