iOS 9 RTL navigation issue - ios

I'm having issues to adopt RTL in my app that will be displayed well on both iOS 9 and 8.
I created a custom UITableViewCell with a UILabel as presented:
In both iOS 9 & 8, when I ran my in a RightToLeft language the labels aligns to the right as expected.
when i push a new ViewController with the navigationController the navigation direction of the UINavigaitonController is different in iOS9 & 8,
in iOS 9 the navigation direction is to the left:
and in iOS 8 the navigation direction is to the right:
I want that by Label on the Cell will be aligned according to the navigationController push animation direction.
so the result on iOS 8 will be as presented, but I still want to keep the respect language direction attribute in the constraint.
does any one knows how the resolve this issue?
Thanks!

One way to resolve it, is just to disable the RTL support, so on both RTL and LTR the result would be the same.
If you want to do it this way, do something like this:
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"9.0")) {
[[UIView appearance] setSemanticContentAttribute:UISemanticContentAttributeForceLeftToRight];
}

Related

iOS 11 Tab Bar items are offset

After upgrading to Xcode 9 and building my app for iOS 11, I have had a problem with the positioning of items in the UITabBar. They are offset to the left (shown in red outline).
I am using just a regular UITabBarController and have not done any custom UI code. I've tried looking for any new UITabBar properties that would effect this, but I can't find anything. Messing with UITabBar itemPositioning property doesn't fix the issue.

How to change navigationBar height in iOS 11?

Apparently changing the navigationBar height faced a new approach in iOS 11.
in previous iOS versions it was possible to change the navigationBar height by hiding the default navigationBar and adding a new one with custom frame:
self.navigationController?.setNavigationBarHidden(true, animated: false)
let customNavigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 64))
self.view.addSubview(customNavigationBar)
But it seems that it is not working in iOS 11 xCode beta. no matter what the new height is, it will always stay at 44.
this is what I've got in xCode 9:
does anyone know how to solve the problem?
Your code is working fine and it´s nothing wrong with it. If you change the background color of your customNavigationBar you´ll see that you´ll get the navigation bar with the desired height. But it seems like it´s an issue with Xcode 9 to hide the default navigation bar.
Your code with:
Xcode 9
Xcode 8
As you can see in the Xcode 9 image, you have the custom navigation bar but the default one does not hide. Probably a bug in Xcode 9, I did not manage to hide it through the Storyboard either.
This seems to be a bug in Xcode 9, bug reports has been filed to Apple.
This is more of a hack till Apple fixes the bug. I was facing the same issue, so I changed the top constraint of the navigation bar from 0 to 20.
Before:
After:
In case your UINavigationBar backgroundColor is something other than white, this will leave the status bar with a white color. You can fix this by adding the following in that particular UIViewController.
let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
let statusBarColor = UIColor.red
statusBarView.backgroundColor = statusBarColor
view.addSubview(statusBarView)
Before:
After:
This seems like a lengthy hack, but still better than going back and compiling using Xcode 8.3.
The only way I could make it work was to delete the current custom Navigation Bar, and apply an embed UINavigationController to the UIViewController.
Editor -> Embed In -> Navigation Controller.
On the new created Navigation Controller properties, on the Utilities (right side bar) menu 'Simulated Metrics' the 'Top Bar' attribute must be specified. In my case I needed the value: 'Opaque Navigation Bar'.
I also set the same value of 'Top Bar' on my UIViewController, just to make sure.
By doing that, a new 'Navigation Item' will be at your disposal, and you can re-add your Bar Button Items.
It's the best I could do while we wait for the Xcode 9 update to fix it.
In iOS 11 we cannot change the navigation bar height, If you want to increase the height we should go with custom view.
Reference:
https://forums.developer.apple.com/thread/88202
Still haven't found how to change it size in pixels. But this is possible to create double navigation bar size (XCode 10.1):
self.navigationController?.navigationBar.prefersLargeTitles = true
Result:
This answer did the job for me.
navigationController.navigationBar.setTitleVerticalPositionAdjustment(CGFloat(10),
forBarMetrics: UIBarMetrics.Default)

Preventing UINavigationController transitions animating upwards with an offset in iOS 11?

I'm updating an app from iOS 10 to iOS 11 with an iOS 9 target and this happens on every segue animation when a navigation bar is involved.
The animation starts with a small offset lower than the height it should be at and then moves to the proper height by the time the view has finished animating.
I'm not doing anything special to the navigation controllers, and it happens to each one in the app. If I programatically hide the navigation bar, the transitions animate normally.
Setting the tableView.contentInsetAdjustmentBehavior to .never in a UINavigationController fixes the problem.
Edit: Actually a better solution is to activate the Under Opaque Bars option for the TableViewController instead.
Otherwise the vertical scroll bars will be behind the iPhone X notch in landscape mode. This worked for me, because I use opaque bars. I don't know what happens if you use translucent bars.
The original solution is described by Prince on the Apple Developer Forums:
After some research ...I found that automaticallyAdjustsScrollViewInsets is deprecated in iOS 11, Now we are to use contentInsetAdjustmentBehavior in UIScrollView type views instead. Setting contentInsetAdjustmentBehavior to .never worked and also the 'UINavigationController translation slide up issue' wouldn't happen if the UINavigationBar is transulcent where the view is under the bar. (Thus the new way of doing the automaticallyAdjustsScrollViewInsets`)
This is not good for Storyboard users because this will have to be done in code.
The top/bottom layout guides were deprecated in iOS11 and I think your issue is connected to this. So you can change the constraints I think.
Read more here.

Issue with autolayout on iOS 7

I'm supporting both iOS 7 and iOS 8 in my app and using storyboard with autolayout to setup my views. I'm having an issue with iOS 7 only.
I have a subview which has a constraint that sets its top space to the bottom of the top layout guide. This makes sure that the subview does not go underneath the translucent navigation bar at the top. It works fine on iOS 8, however on iOS 7 the subview goes underneath the navigation bar right below the status bar.
Any advice on how I can make this work on iOS 7 as well?
Currently I'm using a hack to get this to work on iOS 7, which is below:
override func viewDidLayoutSubviews() {
if NSProcessInfo.instancesRespondToSelector(Selector("isOperatingSystemAtLeastVersion:")) {
// iOS 7 navBar hack
} else {
let navBarHeight = self.navigationController?.navigationBar.intrinsicContentSize().height
self.navHeightConstraint.constant = navBarHeight!
self.view.layoutSubviews()
}
}
Basically I connected the constraint through Interface Builder and I adjust it's constant to the height of the navigation bar if it's iOS 7. If anyone has a better way, please let me know.

iOS 8 Handle status bar on xib files not storyboard

I have an app that I want to upgrade to iOS 8, but since I found that status bar is being hidden on iPhone in landscape mode, I figured that I need to handle such a behaviour.
I solved this issue on iOS 7 by adding a constraint from the top of the navigation bar to the top of the view ( since I am not using Storyboards, some properties or features are not available through xib like top layout guide ) and used this method:
(UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
return UIBarPositionTopAttached;
}
and it was working like charm, but on iOS 8 when status bar is hidden on landscape, navigation bar appears much taller that it is supposed to be. I may handle through constraints and use rotating events, but I believe there must be better ways to handle it.

Resources