-3

i want to change iOS6 application to iOS7.(i.e)i want iOS7 compatibility. When i run my application in iOS7 simulator,view is moving up. Can someone help me?

Muhammad Asif
  • 21
  • 1
  • 7

4 Answers4

0

The full size of the iPhone Screen (non-retina, for simplicity sake, since that what we use with layout coordinates) is 320x480.

In iOS6 and previous, from a developer standpoint, the screen size was actually 320x460, with a 320x20 strip at the top for the status bar. In iOS6, the point x=0, y=0 translates to the iOS7 point of x=0,y=20.

This is because now the status bar is transparent an you can controller how that 320x20 strip at the top looks.

If you want to support both, you need to check which version of iOS they're using, and if they're using iOS7 or greater, you need to increment the origin.y by 20 pretty much everywhere.


Borrowed from this StackOverflow answer, here is how to programmatically determine which version of iOS is running:

NSString *version = [[UIDevice currentDevice] systemVersion];
int ver = [version intValue];
if (ver < 7) {
    //iOS 6 work
} else {
    //iOS 7 related work
}
Community
  • 1
  • 1
nhgrif
  • 61,578
  • 25
  • 134
  • 173
  • `#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)` This macro inside `*_Prefix.pch` can become handy there – rmonjo Jan 18 '14 at 13:49
  • you have a point but still it doesnt solve my question. because. what if iphone 4 and 5 is both ios7. their buttons still different. on my 4, it's clean but in 5 it misalligned. – Muhammad Asif Jan 18 '14 at 15:15
  • You can apply the same logic to differentiating between different screen sizes as well. And this does solve your question. Your question is about the difference between iOS 6 and iOS 7, not about the differences between iPhone 4 and iPhone 5. The difference in Y should be 20 pixels from iOS6 and iOS7, regardless of screensize. If you've got this done, then any alignment problems have to do with different screen sizes, not different iOS versions. Your questions is about iOS versions. – nhgrif Jan 18 '14 at 15:30
0

Because by default viewcontroller have extended edges and it will go under top bar, set it to UIedgeRectNone then view will not go under the top bar.

self.edgesForExtendedLayout = UIRectEdgeNone;
Adnan Aftab
  • 14,377
  • 4
  • 45
  • 54
0

Best way to support both iOS6 and iOS7 without much pain is to pack all your view controllers inside navigation controller (with navigation bar set to hidden if necessary). This will allow to automatically and cleanly handle status bar behaviour changes.

rmonjo
  • 2,675
  • 5
  • 30
  • 37
0

People are nibbling around the correct answer, but haven't given it. I struggled with this for weeks, and finally figured out how to handle it correctly.

How to handle layout differences between iOS 6 and iOS 7 so you can support both without custom code:

The answer is different depending on whether you're using auto-layout or struts and springs.

For auto layout, you tie your top constraints to the "top layout guide", an imaginary line that starts at the content area of the window. It's under any status bar or navigation bar that's present, and moves up if either or both of those items are not shown.

For struts and strings based layout, IB has a mechanism that will let you adjust your view layout automatically.

Select your nib file/storyboard file.

Open the "File inspector" on the right side and look for an item titled "View as". Set that to "iOS 6.1 and earlier. This does several things. It makes your UI look like the app is running under iOS 6, and it makes the geometry work as if it's running under iOS 6.1 rules (the 0.0 point of your content view is under the status bar and your effective screen size is 20 points smaller when the status bar is shown.)

Next, select the views that are pinned to the top of your screen and choose the Size Inspector. (The tab in the utilities area that looks like a ruler). There is a new section of the size inspector called "iOS 6/7 deltas." This lets you specify changes to apply to the selected view when running in the "other" version of iOS than the one you specified above in the file inspector. Since we specified iOS 6, the current layout is using iOS 6 rules, so we want to specify the changes that are needed when running iOS 7 instead. If we had specified "View as iOS 7" in the file inspector, we'd be seeing an iOS 7 layout, and we'd be specifying changes to make when we run under iOS 6. You can do it either way. However, beware. If you have delta values (described below) and then switch this setting, IB moves stuff around on you in very confusing and destructive ways. Don't do that. Pick a value for the "View as" setting and stick with it for your entire app or you will get very confused and frustrated.

You want to make your navigation bars 20 points taller (They then automatically tint the status bar and adjust their layout so their titles and bar button items don't overlap the status bar.)

You also typically want to make views that are pinned to the top of the screen have a delta Y of 20 points to shift them down to make room for the status bar.

If a view is also pinned to the bottom of the screen so it's size adapts with the screen size, you'll probably also want a delta height of -20 pixels.

It takes some tinkering to get everything working right, but by setting your "iOS 6/7 delta" values correctly, you can create IB files that work correctly on both OS versions without any custom code.

If you DO have custom code to do things like tweak your layout for user interface orientation, though, things get really confusing.

Duncan C
  • 128,072
  • 22
  • 173
  • 272