Old app to support for iPhone X? - ios

My old iOS app works well in all iPhone versions(Except iPhone X model). I run into iPhone X simulator and seeing some of the screens gets overlapped at bottom of iPhone X screen. My apps all uiviewcontrollers created programmatically, not designed by story board. So in all view controllers I used (self.view.frame) to find its frame size. In iPhoneX there is safe guard area to design in story board. But how do I calculate safe guard area in runtime. While searching google it gives some sample to find safe guard area which is support from iOS11.. But I want to run my app from ios9? I have lot of uiviewcontrollers in my project .. So can anyone tell me an easiest way to do this task?

One possible way to add a run-time fix for iPhone X layout issues to old (pre-storyboard manual layout) apps (with old pre-11 Deployment targets), is to add Objective C code similar to:
CGRect r0 = self.view.frame;
CGRect r1 = r0;
if (#available(iOS 11.0, *)) {
r1 = self.view.safeAreaLayoutGuide.layoutFrame;
}
if ( r1.size.height < (r0.size.height - 20.0) ) {
// fix top and bottom view overlap outside safe area here
}
inside each UIViewController's viewWillLayoutSubviews method.
The #available check will make this code safe to use under iOS versions prior to iOS 11.

Related

Issue with Safe Area - Fine on iPhone X, not on others

So I'm trying to update my app for the iPhone X (a little late to the game, I know), and I enabled safe area, and fixed (supposedly) all my constraints to match. It looks perfect on the iPhone X. But for some reason, on all other iPhones, it still accounts for the iPhone X's notch, despite Safe Area correctly displaying where the UI should start and end. I'm at a loss. None of the constraints in question are hard coded, I set them all to the "standard" value (or so I believe).
storyboard (first button is actually the talk bubble, which is just a static image, second is the paw print, which is an actual button)
messed up iPhone 8 (bubble and ui elements should be at very top and bottom)
Here's my storyboard file: https://ufile.io/35zvs
UPDATE: image for ercell0
You are using standard spacing for top and bottom for your Banner View with a required priority. try setting this to superView: 0 or safeArea: 0 and see if that corrects the issue for you.
The updated view:
Can you change ViewAs from iPhoneX to iPhone8, and attach an image?
Other iphones your are testing on are running iOS11 or older?
If running older versions, safe-area won't be able to help with the alignment. For pre iOS11, use the constraints you were using previously or Layout Anchors.

How to make compatible existing app to iPhone X

We have an application with 6 to 8 screens which was developed by Swift 3.2 version. And I am using Size classes (Auto Resize),not using autolayouts for all devices its working fine.
But, Now, We want to make it compatible with iPhone X device.
While we testing app in iPhone X, there are lot of issues on top, bottom views and even centre of the screen in Subviews.
I have seen, few forums which were told, "Use adaptive Sage Guide" in Story board files of UI, and issue would be solved. But, Event I tried that, still lot of gaps and issues coming bottom and top while testing app with iPhone X.
So, how to make compatible with iPhone X with my existing code, do I need to change everything in programmatically for below iPhone X and iPhone X, or is there anything there?
Can anyone suggest me, how to proceed for this.
Note : We are using Xcode 9.2
It's not just an iPhone X thing, it's also an iOS 11 thing. iOS 11 introduces a brand new inset adjustment API that deprecates most (maybe all?) of what preceded it. And with iPhone X's physical design, even more attention to safe areas must be made.
So get used to writing these:
if #available(iOS 11.0, *) {
// new iOS 11 syntax
someView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
} else {
// pre-iOS 11 syntax
someView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor).isActive = true
}
the safeAreaLayoutGuide is now a property of the view itself and it's more intuitive, IMO. More examples of the new API syntax:
someView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
someView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor).isActive = true
someView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true
And if you're interested in getting inset values:
if #available(iOS 11.0, *) {
someViewAnchor.constant = view.safeAreaInsets.bottom
} else {
someViewAnchor.constant = bottomLayoutGuide.length
}
If you’re using storyboards, you should open them now, go the file
inspector, then select the Use Safe Area Layout guide checkbox – that
will switch you over to the new system.
https://www.hackingwithswift.com/articles/12/how-to-update-your-app-design-for-iphone-x
After adding Safe Area Guides you need to do little changes in constraints attribute like those constraints which are using superview.top and superview.bottom of the screen after applying the Safe Guide the superview need to change to the Safe Area like in the picture below

Why autolayout behaves different in iOS 7 and iOS 8?

For example: I have set in a storyboard scene a vertical space constraint from de bottom of a UIButton to the bottom of the superview with a constant of 20. When running in an iOS 8 device, this is correctly shown, but when running in an iOS 7 device, it looks like this constant becomes higher and the button is shown upper in the screen... I don't understand why this happens, since autolayout is supposed to be available since iOS 7.
Any help? I don`t know how to handle this.
Thanks in advance
One of new things in iOS 8 is the Layout Margin. Layout Margin is a new property available in UIView for iOS 8. So, any objects inherit from UIView will have this property. If you are developing the app for both iOS 7 and iOS 8, you should not use Layout Margin (or use layout margin in a smart way).
So, if you have any constraints related to layout margin and you didn’t do a proper check before launching the app on iOS 7 devices, the app might crash or the arrangement of the objects might be out of order.
Whenever you are trying to add new constraints from the storyboard in XCode 6, “Constrain to Margins” is ticked by default. The meaning of this selection is to add constraints with the new property in iOS 8.
If the deployment target of your app is iOS 7 and above and any of your constraints have this layout margin, the XCode will complain with the warning “Layout attributes relative to the layout margin on iOS prior to 8.0″.
If you are developing the app for both iOS 7 and 8, it is best to “Untick” the Constrain to Margins.
Reference: you should also check this great tutorial

Default UIProgressView rendering on iOS7 using iOS6 SDK

I am experience a rendering bug when using the default progress view. Rather than being 9px tall, the view is clipped to about 4px when using the default progress view. My app is built with the iOS6 SDK, and the issue appear when running on a iOS7 device. The interface is built with interface builder.
Is there a simple fix for this issue? Switching the style from "Default" to "Bar" in interface builder fixes the problem, but that changes the appearance.
Setting the frame in code helped me solve this.
#iPP 's answer is not the best. Setting the frame in code will cause your code to be riddled with iOS version checks, and that code tends to get very complicated when supporting multiple device orientations.
I think the best way is to use new feature "iOS 6/7 Deltas" in Xcode 5.
And "iOS 6/7 Deltas" key usage is:
When Auto Layout is turned off, you will notice an area in the sizing tab of the utility area (right pane) of Interface Builder that allows you to set iOS 6/7 Deltas. Deltas can be set individually for each view and work as you would expect. If your storyboard or nib is set to view as iOS 6, then setting the deltas will cause that view to be shifted and/or resized by the set delta amount when run in iOS 7. Alternately, if your storyboard or nib is set to view in iOS 7, then the deltas will be applied when run in iOS 6. Both of these tools help you to support older versions of iOS alongside iOS 7
for UIProgressView, here you can try to set "delta Y" to be -7px, because iOS 7 just reduce the Y origin of UIProgressView by 7 px, so when running in iOS7, we should give it back the 7px.
It's like the iOS7 cut the progress view use the iOS7 Style's frame.
You have two ways.
1. set the progress view style ---bar, you can do this in the nib file or code.
2. use the code to set the frame. Something like:
progressView.frame = CGRectMake(x,y,w,h);
The second will face the layout issue when you rotate or change the layout.
So the easiest way is set the progress view's style.

How to manage Autolayout constraints which can be applicable for iOS 7 & iOS 6.0 both

I have created the new iOS project in xCode 5 with deployment target 6.0 and Apply Pin constraint [Bottom space to superview] to make AutoLayout applicable for iOS 7 as well iOS 6.0 with different devices but
When I choose option "View as : " : iOS 7.0 & later Button looks like following
then When I change option "View as : " : iOS 6.0 & earlier the button looks like following
How Do I manage constrait such a way that make applicable with iOS 6.0 & iOS 7.0 both ?
Thanks in advance !!
I had a similar issue in my story board, I searched a lot with no hope and ended up removing all constrains by:
Editor -> Resolve Auto-Layout Issues -> Clear all constraints in view controller
Then reordering again, this solved most of my issues.
First from Apple Transition Guide:
If business reasons require you to continue supporting iOS 6 or
earlier, you need to choose the most practical way to update the app
for iOS 7. The techniques you choose can differ, but the overall
advice remains the same: First, focus on redesigning the app for iOS
7. Then, bring the changes to the iOS 6 version as appropriate.
This means that you could face some issues in prior iOS versions, especially in layout and you need to re-layout your controls under iOS7 then test them under iOS6.
I'm developing an app that runs on both iOS 6 and iOS 7. Some of my buttons appear the same on both iOS 6 and iOS 7 and some appear to be vertically smaller on iOS 6 but normal on iOS 7. I looked and the difference appears to be that on the buttons which maintain their size, I am using a background image like so.
//...background button images are 33wx44h and 66wx88h. these correspond to the
// two name variations; <name>.png and <name>#2x.png. the former is used for
// standard resolution screens and the latter for retina screens.
// the UIEdgeInsetsMake is specifically set to 0, 16, 0, 16 (tp,lf,by,rt) so
// that we have no vertical stretching because Apple's preferred button size,
// vertically, is 44. horizontally, the button is 33w and we lock 16 from
// the left and 16 from the right to leave only a single vertical row of pixels
// to be stretched horozontally; which is the most efficient; processing wise.
UIEdgeInsets insets = UIEdgeInsetsMake( 00.0f,16.0f,00.0f,16.0f ); // tp,lf,bt,rt
UIIMage * btnImage = [[UIImage imageNamed: myImage ]
resizableImageWithCapInsets: insets];
[button setBackgroundImage: btnImage
forState: UIControlStateNormal];
I'm thinking that in my situation, I can put a background image into all of them, even if it is transparent, to maintain the same look.
Hope that's helpful.

Resources