UINavigationBar back button not showing on iPhone X iOS 11 - uinavigationbar

I am facing an issue, When i run my app on iPhone SE simulator it shows back button on nav bar like this.
But when i run the same app on iPhone X, iPhone 8 and iPhone 8 plus iOS 11 and XCode 9 there is no back button on nav bar and its for all ViewControllers not for specific viewController. Here is the example
Can anyone tell why is this happening.

I had the issue where the back button was only a little bit. In the debugging console it was showing a few broken constraints in the navigation bar.
I found this line in the app delegate to be the issue.
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment( // Remove the text "Back" from the back button so only the back arrow is visible
UIOffset(horizontal: -100, vertical:-100),
for: UIBarMetrics.default
)
try and find any appearance api calls in your code and see if you might be modifying the bar button offsets.

After some effort i came to know that i am setting the view's leading space before setting as NavBarTitleView
navView.viewLeadingConstraint.constant = (UIDevice().isIPhone5 || UIDevice().isIPhone4) ? -15:-40
due to above code my back button hides so i removed above line of code and add following method in NavView which resolve my problem.
override var intrinsicContentSize: CGSize {
return UILayoutFittingExpandedSize
}

Related

Properties assigned to UIButton in ViewController.swift and segue works on Simulator but not on Device

I have an extremely bizarre problem. I created a UIButton and put it on my ViewController storyboard. I added a segue from the Button to another ViewController by pressing control and dragging. I also added an outlet to the corresponding ViewController file and added a border color and width (to the button). The segue and the button border work fine on the simulator but on a device the button border does not show up and the segue does not work.
The only thing I can think of that could be causing the problem is that a little while ago I accidentally deleted my Main.storyboard, so I dragged it from my trash back to my Xcode project. But I am pretty sure my app has worked on the device even after that incident. I wasn't sure if my viewDidLoad method was being fired (since that is where I set my border color and width for the button) so I added a print statement and found out that it was indeed being called. Take a look at the code below...
override func viewDidLoad() {
super.viewDidLoad()
print("Begin Setup Process...")
// Do any additional setup after loading the view.
calibrateButton.layer.borderColor = UIColor.white.cgColor
calibrateButton.layer.borderWidth = 3
}
How would I get this to work on my device as well? What I am doing wrong
Assign Your Border Styling Here...
Try adding the code to change layer properties of calibrateButton in viewDidLayoutSubviews(), i.e.
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
calibrateButton.layer.borderColor = UIColor.white.cgColor
calibrateButton.layer.borderWidth = 3
}
Also, since you're giving borderColor as white, that might not be visible if the calibrateButton is placed on a white background. Try changing it to something else that is more visible, red for example.
First try in viewDidAppear(), if it works then cut and paste it in viewDidLayoutSubviews().
I finally solved the issue. The problem was that I didn't have a height constraint on my button. I am still not exactly sure why or how this issue occurred. Why couldn I see the button text but not the border? If the segue was not working there must have been a view on top of the button that was preventing it from going off. But anyway adding a height constraint solved the problem. In answering my own question I realize that the title of my question is misleading in relation to the solution of the problem. This problem, in the end had nothing to do with wether the app was running on a simulator or the device. I just assumed it was a device issue since it was working fine on my iPhone XR simulator but not my actual iPhone 6s. However the actual problem was the screen size and how my constraints adapted to it.

Code or setting to hide or change color of gesture bar (also called app switcher) iOS 10+

I need to make the screen go completely black in my app, but I still see the new thin line at the bottom that replaced the physical button in iPhone Xr and Xs.
I have looked at settings and googled like crazy. I called apple tech support to get the name of the bar itself. They said either 'gesture bar' or 'app switcher bar'. Do you know the code or setting required to change it's color or make it invisible?
N/A
Hoping to black out entire screen, but the thin line bar at the bottom shows up (this is not the tab bar or navigation items, but rather the new bar the user swipes up in the newer phones.)
You can use this UIViewController API that hide "Home Indicator".
https://developer.apple.com/documentation/uikit/uiviewcontroller/2887510-prefershomeindicatorautohidden
Override the following method on the ViewController you want to hide the indicator.
override var prefersHomeIndicatorAutoHidden: Bool {
return true
}
prefersHomeIndicatorAutoHidden
https://developer.apple.com/documentation/uikit/uiviewcontroller/2887510-prefershomeindicatorautohidden
setNeedsUpdateOfHomeIndicatorAutoHidden()
https://developer.apple.com/documentation/uikit/uiviewcontroller/2887509-setneedsupdateofhomeindicatoraut
childForHomeIndicatorAutoHidden
https://developer.apple.com/documentation/uikit/uiviewcontroller/2887508-childforhomeindicatorautohidden

TableView pushed down after view change

I'm kind of new with ios development with swift 4, so I'm testing some functionalities.
I have a tableview inside a normal UIViewController:
The space left blank is intentionally, as I have some custom tabs.
When I show a detail from a table cell element, and then press back button, the table view gets pushed down (and up). Please see this where I show the problem.
The iphone is a SE with ios10. In simulations with iOS11, this does not happen. Developing in MacOS Sierra 10.12.6 with xCode 9.2.
Any clue on how to fix this?
EDIT:
Using the view debugger, I got this:
The selected area is a UITableWrapperView element. Behind it, is the UITableView, which preserve its constrains.
set
self.tableView.bounces = false
Or put this in viewDidAppear
let offset = CGPoint.init(x: 0, y:0)
self.tableView.setContentOffset(offset, animated: false)
It can happen because of SafeArea... Check you constraint which connects tableView top with navigation bar.
You can also try placing blank UIView between Navigation bar and tableView. Your custom tabs should be in this view. So tableView will be connected with the nearest view (which you have just added) and should not bounce.
Thats a really weird behavior. I recommend you to use the Xcode view debugger. You would be able to examine dimensions and constraints values by using size inspector.
The code where you set up your tableview, try implementing it in the method viewDidLayoutSubviews(in case you are doing it in viewDidLoad).
override func viewDidLayoutSubviews() {
//mention your tableview setup code here
}
A similar thing happened to me, and this method came quite handy. Hope this helps.
Try this for iOS 11.0
tableView.contentInsetAdjustmentBehavior = .never

UIPageViewController page controls too close to home bar on iPhone X iOS 11

I have a program with one main view controller, which includes a button that the user can tap to display 4 pages of "Quick Help" via a UIPageViewController. The 4 pages are QuickHelpViewController0ID - QuickHelpViewController3ID, and each is a standard UIViewController. When they tap the button, I run this:
-(void)showQuickHelp
{
// Load the quick help page view controller
self.quickHelpPageVC = [self.storyboard instantiateViewControllerWithIdentifier:#"QuickHelpPageViewControllerID"];
self.quickHelpPageVC.dataSource = self;
// Create initial quick help page
UIViewController *quickHelpVCA = [self quickHelpVCForPageIndex:0];
NSArray <UIViewController *> *quickHelpVCs = #[quickHelpVCA];
// And assign it to the page VC
[self.quickHelpPageVC setViewControllers:quickHelpVCs direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
[self presentViewController:_quickHelpPageVC animated:YES completion:nil];
} // showQuickHelp:
I also provide a UIPageViewControllerDataSource to create each of the 4 pages as needed when the user scrolls to the next/previous page.
This works fine on iOS 9.3 and 10.x. It also works on 11.0 for all devices except the iPhone X (simulator). On that, the row of 4 page indicator dots is way down at the bottom of the screen, only 1 or 2 pixels above the new "home bar" that iOS 11 provides (slide up to switch apps, etc).
I found a video from Apple called Building Apps for iPhone X where the developer discusses fixing a similar problem, but in that case his solution was to simply change auto-layout to constrain a child UIPageControl to the bottom "safe area" instead of the traditional bottom layout guide. But I'm not using a UIPageControl on another view controller; I'm using a UIPageViewController, and I don't see any way to control the location of the page controls along the bottom of the window. (Yes, I've enabled the "Use Safe Area Layout Guides" option in Interface Builder.)
I can't imagine that iOS 11 sizes the UIPageViewController incorrectly by default in my scenario, nor do I see any obvious way to fix it. Any suggestions?
The fix for this is coming in 11.2
https://9to5mac.com/2017/10/30/ios-11-2-beta-1/
UIKit -
Resolved Issues
Displaying a page control in UIPageViewController on an iPhone X no longer overlaps the home indicator at the bottom of the screen. (34478195)
I had the same issue, but found that if I uncheck the 'Extend Edges - Under Bottom Bars' on the main view controller, the dots move up and appear correctly for iPhone X on the simulator. Unfortunately it also moves the dots up on all other devices... might not be an issue if there isn't too much on the page, but for me it truncated one page with lots of text on it.
It definitely looks like a bug, so I'll wait for Apple to hopefully fix the issue, as I'd rather not put nasty hacks to programmatically change the extend edges under bottom bars flag just for iPhone X

iOS 11 SearchDisplayController shows black status bar

I know SearchDisplayController is deprecated, but Storyboard still supports it, and it is an easy way to present tableViewController on top of your view controller. I have been using it, and I would still prefer to use that. And in iOS 11, when I run my app, the status bar of the SearchDisplayController. after the search bar is focused, is pitch BLACK. Does anyone know how to solve this bug? Also if you realize, the margins of the searcher is off. I am using the default iOS 11 searchbar. Below is attached screenshot:
Have you tried to set the extendedLayoutIncludesOpaqueBars property to true?
searchDisplayController.extendedLayoutIncludesOpaqueBars = true
This is not the best solution actually, but It works to change status bar color.
if let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView {
statusBar.backgroundColor = //YOUR COLOR HERE
}
Keep in mind this will affect the whole app. If you need to change some views only then save the previous color to restore it.
Regards.

Resources