IOS 5 and IOS6 have different result of interface orientation - ios

Hi I create app for ios 5 and 6, I need to reposition my button depend on interface orientation. Problem is that:
ios 5: it return UIInterfaceOrientationLandscapeRight while ios 6 it return UIInterfaceOrientationLandscapeLeft.
So I cannot reposition my button correctly
I don't know how to deal with this, or I need to change something in setting.
Thank you for your help!

I have no idea why the orientations are different.But maybe you can solve the problem like this
UIDevice *device = [UIDevice currentDevice];
NSString *tem = device.systemVersion;
if ([tem intValue]>=6){
}
else if{
}

Related

Presented UIViewController refuses to lay out with landscape orientation

I am updating a 5-year-old app (originally written for iOS 3!). I have made decent inroads in using autolayout and addressing deprecation warnings. But the old technique used for presenting a different view controller when the device is rotated no longer works reliably.
- (void)orientationChanged:(NSNotification *)notification {
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (deviceOrientation == UIInterfaceOrientationLandscapeRight && !showingOtherVC) {
// switch to other VC
othervc.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:othervc animated:YES completion:nil];
[self resignFirstResponder];
}
The other view controller does appear, but it's laid out sideways, for a portrait screen, not landscape, even though the device is in a landscape orientation.
How can I update this in a reasonably easy way (i.e., not a rewrite in Swift, not restructuring the app with storyboards — which Xcode doesn't seem to facilitate via copy/paste)? And, for the benefit of others who may happen on this question, what would be the more correct way to achieve this result (new VC on orientation change) if I were writing this from scratch?
Thank you.
This was a really stupid error, but in case someone else makes it and ends up here, this was the problem.
Instead of correctly returning the mask constant:
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
return (UIInterfaceOrientationMaskLandscapeRight);
}
I was returning this other constant that autocomplete gave me:
-(UIInterfaceOrientationMask)supportedInterfaceOrientations {
return (UIInterfaceOrientationLandscapeRight);
}

preferredContentSize not working in ios 7?

I am using modalPresentationStyle of type UIModalPresentationFormSheet to show my view.I want specific size of the view so using preferredContentSize which working in iOS 8 and showing exact how I wanted but same breaks for iOS 7 it's come as full sheet.View size changed.
Where as I wanted like below image
Any idea?
Please check below conditional code for iOS 8.x and iOS 7
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0"))
{
modalController.preferredContentSize = CGSizeMake(frameSize.x, frameSize.y);
}
else
{
modalController.view.superview.frame = CGRectMake((screenWidth - frameSize.x)/2, (screenHeight - frameSize.y)/2, frameSize.x, frameSize.y);
}
Hope this will help you.

Landscape for only certain devices in iOS 8.0

With iOS 8.0 in Xcode 6, there is nowhere where I can see that you can specify for each device if you want it portrait or landscape...
I want to have all iPhones only portrait except 6 Plus which should be both portrait and landscape. And I want all iPads to be both portrait and landscape.
Is there a way to do this or even a workaround it?
To make the 6+ different than other iPhones you'll need to implement supportedInterfaceOrientations something like this:
- (NSUInteger)supportedInterfaceOrientations
{
if (iPadOrPhonePlus()) {
return UIInterfaceOrientationMaskAll;
}
return UIInterfaceOrientationMaskPortrait;
}
I haven't settled on a way I like for that helper method but you can start with this:
.#define iPadOrPhonePlus() ((UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) || [[UIScreen mainScreen] scale] > 2)
ignore the . before the #define SO was formatting it strangely without that.

how to set iOS 6/7 Deltas programmatically

I was developing a UISplitView app by using Xcode 4.6 when I left iOS6 I had design:
Now I migrate to new Xcode5 and now I have this design:
UINavigationBar overlaps completelly my UISearchBar...
Leo Natan told me about using a iOS 6/7 Deltas but since I'm creating and adding my UISplitViewControllers programmatically,
this may doesn't work I need to set the iOS 6/7 programmatically but I don't know how, any help I'll appreciate
In iOS 7 there are now extended edges, and that's why navigation bar overlaping the searchbar. You can set self.edgesForExtendedLayout = UIRectEdgeNone; this is UIVewControlelr property.
You can also make checks depending on version of iOS and You can do things depending on current version of iOS in device.
NSString *version = [[UIDevice currentDevice] systemVersion];
int ver = [version intValue];
if (ver < 7){
//iOS 6 work
}
else{
//iOS 7 related work
}
Also, you can use NSFoundationVersionNumber
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
// > iOS7
} else {
// <= iOS6
}
You can create a makro for solve this problem.
it is useful for me.
#define iOS7Delta (([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0 ) ? 20 : 0 )
If the view's embedded in a UINavigationController -
simply untick "Translucent" for your root navigation bar.
In storyboard, select Navigation Controller Scene,
next select Navigation Bar and in Attributes Inspector (Utilities - 4 tab)
untick "Translucent"

Query launch image at runtime

I'd like to have a nice start of my app by fading from the splash screen (UILaunchImageFile) into the main screen. Easy thing, I thought, just show an UIImageView with the splash screen as the very first view and then make a transition animation.
The problem is, since this is an iPad app with all four orientations supported, and splash screens for all these orientations, I would need to query which splash screen was used. I could query the current device rotation and select the image accordingly, but I wonder whether there's a better way.
So, can I query somehow which launch image was used during app start or do I need to ask for the device's current UI orientation and chose the file accordingly ?
No, you can't do this automagically. Querying the device rotation and selecting an image based on that is perfectly fine.
You really only need Portrait or Landscape in this situation though, assuming you are rotating your view properly.
As already stated by Joshua you cannot, as far as I am aware.
In case this might help someone else, if you are using asset catelogs the following code should provide the correct launch image for the current interface orientation.
NSString *suffix = nil;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
suffix = [[UIScreen mainScreen] bounds].size.height >= 568.0f ? #"-568h#2x" : #"#2x";
}
else {
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
suffix = UIInterfaceOrientationIsPortrait(orientation) ? #"-Portrait" : #"-Landscape";
suffix = [UIScreen mainScreen].scale == 2.0 ? [suffix stringByAppendingString:#"#2x~ipad"] : [suffix stringByAppendingString:#"~ipad"];
}
NSString *launchImageName = [NSString stringWithFormat:#"LaunchImage-700%#.png",suffix];

Resources