The question might sound silly but I guess it may be a matter of interest for many developers.
With the launch of Xcode-5 & development being targeted to iOS7, how do I maintain backward compatibility to make the app run properly on older versions of iOS ?
I see the big challenge with UINavigationControllerlayout. With Navigation bar visible, the CGRectMake(0,0, 50, 50) will take the upper left corner just after Navigationbar but now in iOS-7, it goes behind. I know the solution to fix this here, but how the same can work for older version when this feature is newly introduced.
What else places do I need to bridge this gap (the backward compatibility)
Use viewController.topLayoutGuide.length instead of 0 in manual layout, see here.
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have an app running on iOS 7. Now I want to support is 6+. Here is screenshot on iOS 7.
When I changed the deployment target to 6.0, things are positioned strangely on the screen. It shifted everything downward.
How can I fix it? Do I have to handle the positioning manually according to iOS version?
BTW I am not using auto layout.
At least two ways to handle this:
1. The big difference here is 0 in the y direction is actually 66px higher on screen in iOS7, by default, since views extends under the navigation bar and status bar.
If you're using storyboards, the simplest fix is to uncheck the 'under top bars' and 'under bottom bars' option when selecting your view controller.
However, this isn't the direction Apple's going in iOS7, though.
2. You can do the same as #1 by using the edgesForExtendedLayout property of your view controller.
3. If you're not using autolayout, then you can select your main view and change the iOS6/7 deltas option. In this case, you would want to enter -66 in the delta-Y box and 66 in the delta-height box. These are essentially insets that are applied to views when your app runs on iOS6.
4. Use autolayout with appropriate constraints and it should just work. I say should because it's easier to use autolayout if you think of layout in terms of relationships instead of frames and positions.
These are basics of iOS 7 UI. You have to read the transition docs, it's a MUST for iOS developers(you have to login ofcourse) :
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/TransitionGuide/index.html#//apple_ref/doc/uid/TP40013174
And you definitely have to watch the WWDC movies, especially:
building user interfaces for ios 7 (video number 201)
customizing your app's appearance for ios 7 (video number 214)
You can find them for free in iTunes.
Regarding you question:
It is the new iOS 7 approach that causes you issue. In iOS 7, the nav bar is translucent by deafult. In iOS 6 its not.
In case of translucency - the origin {0,0} is right under the navBar. So if the UIView with such origin in the first case will be under the nav bar, in second case - bellow. You can even notice the new iOS 7 approach of making everything under it nice and blurry - thanks to translucency.
To fix it, use
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
} else {
// Load resources for iOS 7 or later
}
and do the proper code formatting, like changing the origin in different cases.
It is very well explained, and so many more important updates in the docs and the videos that you really should check out, if you want not just to blindly develop, but also understand what are you doing.
Make a backup or copy
Switch back the "View as" property from 7.0 and later to iOS 6.1 and Earlier.
Beware, all your iOS7 prior settings will be lose after switching back
Rearrange the x coordinate to all subviews because everything will be a bit downer now.
(Because in iOS7 the default x=0 coordinates are under the navigation and status bar, and in pre-iOS7 it starts right above the navigation bar or status bar)
At viewDidLoad add the following line:
if ([self respondsToSelector:#selector(setEdgesForExtendedLayout:)]) [self setEdgesForExtendedLayout:UIRectEdgeNone];
Did you Try
self.edgesForExtendedLayout=UIRectEdgeNone;
Try
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
// here you go with iOS 7
self.edgesForExtendedLayout=UIRectEdgeNone;
}
Consider the above's IB objects listing. Siblings further down the list should be on top of the siblings listed further up when rendered on the screen.
Under Xcode 4.5.2, everything is ok if iphone simulator 5.1 is used. But for simulator 6.0 the map just covers everything. The same if using actual devices (phones) for testing.
Hope that somebody knowledgeable could help.
Please also add comments if you do not (or do) find such a problem on simulator 6.0. Chances are the problem is related to how my project is setup.
Update :
Have setup a new test project with iOS 6 map view myself. There seems to be no problem with z-order at all. So the problem could relate to my code. Unfortunately, quite a lot have already been written, there wouldn't be enough time to go over everything for the time being. I suspect that it has something to do with the rootViewController property. My project initially followed a older scheme in which rootViewController was not used ...
I dont know if that order is reliable at all -- in the past definitly not and I am not conviced it is today :D. (even though apple claims it :D)
see: IPhone Interface Builder: Z-Index, Z-order of a button, image, ui element, etc?
(the 3rd answer currently. 7 votes)
The problem is solved by calling Window's bringSubviewToFront method. But I believe a better and more proper solution can be found given enough time.
Been trying to find some tips on suggested approach for this and not having much luck.
All I'm looking for is to know what is the best approach to handle custom layouts for portrait/landscape modes.
I've seen some posts say in the storyboard add 2 views to the same ViewController and show/hide based on orientation change while some people suggest to use a totally separate ViewController for each orientation.
Which of this is the preferred method. I'm just starting my application, So I'd rather go for the widely accepted method than have to deal with complications later on.
Apple documentation still keeps talking about nib files and not storyboards in this aspect, so not being of much help.
My main focus is performance (I'm fine with having to code stuff instead of depend on the graphical interface for it). separate ViewControllers seem to keep the code in a clean way however if that involves populating views / clearing them every time orientation changes, seems kind of expensive(not sure if it is relevant).
Also if each scene in the application has 2 layouts then managing them I'm not sure how much of a pain it's going to be when the application grows big.
Please point me in a suitable approach for my case,
am not concerned about backwards compatibility. Just worried about the latest Xcode and ios6 if it matters for the decision
Thanks
I would say this really depends on the level of customization of the UI in portrait vs landscape. A large number of implementations I have done can be handled by either autoresizing/autolayout when switching orientation, or simply moving the elements yourself when the UI is rotated and the callbacks are fired. Moving the elements around should not be an expensive operation at all as it is a very common occurrence (again this depends on the complexity of your UI though).
I have a view (a couple of them actually) with a standard search bar at the bottom. When the user touches the search bar, I need to move the search bar up so it's not hidden by the keyboard, then down again when the keyboard is dismissed.
I do this the same way as everybody else, by observing UIKeyboardWillShowNotification and UIKeyboardWillHideNotification. From these notifications, I get the height of the keyboard, and that tells me where to put the bottom edge of the search bar. It works perfectly, except for rare cases when the search bar doesn't animate, or doesn't animate far enough, and vanishes behind the keyboard. I have seen this a handful of times out of hundreds of tries with myself and my QA people testing on iPhones and iPods. Just once, I saw the search bar fly off the top of the screen as the keyboard came up. We've never seen any of this on the simulator, and we see it more often on the iPod than the iPhone. We are running iOS 4.x, mostly 4.3.3.
So I can think of two possibilities. One is that very occasionally UIKeyboardWillShowNotification is not sent and the other is that the data in the notification is wrong. The second one would explain the one case where the search bar flew off the top of the screen.
And then of course it is possible that my code is wrong in some very devious way; but the scenario is so simple -- enter the view and tap the search bar -- that I can't see how a bug in my code could cause these rare and intermittent failures.
If anyone can offer insight, I would be very grateful.
I finally discovered the answer to my question, and it's interesting. To cut to the chase, my search bar is animating into the wrong position; in some cases it's still behind the keyboard, and in others it's off the top of the screen. This is not caused by wrong data in the notification, but by a bug in accessing the height member of a CGSize or the y member of a CGPoint.
Specifically: in certain scenarios, when you write mySize.height, the generated code accesses mySize.width. If you are reading, you get the value of mySize.width; if you are writing, you clobber mySize.width. Similarly, myPoint.y actually accesses myPoint.x.
You may never see this problem. I only saw it on older iPod touch devices running iOS 4.2.1, and only in Release builds, and only when compiling with Apple LLVM Compiler 3.0, and then maybe only sometimes. But I reported it to Apple and they say it's a duplicate of a known bug (#10043857) that they are addressing. Connecting a few dots, I am guessing that it's somewhere in the compiler chain in Xcode 4.2.
The workaround is to take the address of the CGSize or CGPoint struct, then use pointer arithmetic to access the desired member. I wrote a set of little helper functions to do this, and I call them all over my app's code.
After I've upgraded to Snow Leopard and Xcode 3.2, everything was screwed up. It took a while for me to figure out the whole evil was that my old Xcode installation was not really "updated", but replaced. So just everything was gone. All SDKs, Settings, everything.
So Code Sense did not work because of no SDK available, and all the other problems mentioned also just appeared because of that. So now, after re-installing all SDK's, Xcode seems to work fine. Well, almost: Simulator 2.2.1 is gone, which feels more like a punishment for upgrading fast to SL.
After all I decided to re-edit my question to prevent irritations. However, here in short what problems I had, so the answers still match:
1) The font was totally different
2) New Xcode didn't autocomplete CGRectMake and provided no parameter info, for instance. That was because of all missing SDK's and my wrong believe that it was an "upgrade" rather than a whole new replace.
3) New Xcode didn't highlight same symbols in scope. Same problem cause like above.
4) New Xcode never autocompleted anything. Same problem cause like above.
Off topic, but I feel everyone in the world must know:
The new Quicktime Player sucks. They removed all important controls like speed and sound tuning, which was always welcome on bad video trainings. Hopefully, they will add those important features again soon.
You are the first person I know of who feels that Xcode 3.2 is not a significant step forward. In response to your issues:
1) The new default font for Xcode is Menlo, as opposed to the previous Monaco. You can easily change this back under Xcode | Preferences | Fonts & Colors. Personally, I prefer Anonymous Pro or Inconsolata.
2) It sounds like your Code Sense index for your project might be messed up, causing the autocompletion issues that you're seeing. Click on the root of your project in Xcode, bring up the inspector, go to the General tab, and click on the Rebuild Code Sense Index button. I had this happen to me once, and that took care of the problem.
3) If I double-click on a symbol to highlight it, a dashed underline does appear below all instances of the symbol within the scope. As has been pointed out, right-clicking on the symbol will let you Edit All in Scope, a really nice addition to the editor.
4) See 2) above.
As far as the Quicktime Player, you can install the old Quicktime 7 as an optional player so that you can gain back some of the functionality that hasn't made it into the new player. The whole point of the new player is to start from scratch with the video playback frameworks, enabling much better performance (my MacBook Air can play 720p video without stuttering now). The missing functionality will be added back in, as it was with the new iMovie.
The point of Snow Leopard was not to remove capabilities, but to refine what was there and to strip out obsolete elements. In the case of Xcode 3.2, they added the integrated Clang LLVM compiler team, the integrated Clang Static Analyzer (worth the upgrade alone), a much improved documentation browser, and many new capabilities to the editor (like the Edit All in Scope mentioned above).
As far as iPhone OS 2.x support, you can build for it in Snow Leopard, but the Snow Leopard version of the iPhone Simulator only runs the 3.x OS. Apple clearly wants you to target the 3.x OS going forward.
1) Change the font in the Xcode preferences.
2) Xcode preferences "Code Sense"
3) Select the symbol and hover over it, after a short delay a small grey triangle appears to the right of the symbol, left click on it and select "Edit All in Scope". Not quite the same.
4) Same as 2 above.
Both 2 and 4 work for me, I must have different preference settings.
I use Mac OS X 10.6.1 and Xcode 3.2:
My fonts are nice
Works for me
Works for me
Maybe you should try to reinstall.
As noted, all of the things you list can be addressed with preference settings in XCode - for #3, check your setting for "Edit All In Scope" under "Code Sense" in Settings.