I am developing a landscape application with orientation UIInterfaceOrientationMaskPortrait, except one view controller( used for uploading image) having orientation UIInterfaceOrientationMaskLandscapeRight.
How orientation change should ideally work
When users plan to upload image, orientation change from UIInterfaceOrientationMaskLandscapeRight to UIInterfaceOrientationMaskPortrait,
When uploading finished, change orientation UIInterfaceOrientationMaskPortrait to UIInterfaceOrientationMaskLandscapeRight, .
Issue:
When I tap the icon then into the application, the application layout is right, but if I flat device on the desk for times, next time I get into, application layout is wrong.
For example:
First time:
aView.width = 568 * 0.6;
aView.height = 320 * 0.6;
but in other cases:
aView.width = 320 * 0.6;
aView.height = 568 * 0.6;
seems like width and height exchanged
Suggestions are appreciated!
Related
Our current version of our iphone application in the app store simply stretches the layout to fill the iphone 6 and 6+. After the xcode 7 update, the app just runs as it would on an iphone 4 with black bars at the top. I understand that adding a launch storyboard resolves this. The problem then is that our layout is out of whack on the 6 and 6+.
Obviously fixing the layout to adapt to these screen sizes is what needs to be done, but we are in a pinch and just need to get a behind the scenes function update pushed out to our users ASAP. Is there anyway to go back to the old behavior where the UIView would just stretch to fill the screens?
This won't be an immediate fix, but it's a quick patch that might be worth trying.
If your view is always in portrait, this should work for you. If it requires rotating or a UISplitViewController on iPhone 6(s)+, then it might not.
Scale each subview in your view controller for the new screen size. Declare a couple macros for the device screen size:
#define kScreenWidth [UIScreen mainScreen].bounds.size.width
#define kScreenHeight [UIScreen mainScreen].bounds.size.height
Then add a method to your view controllers that goes through all subviews to resize each view proportionately based on an iPhone 4 screen size.
- (void)resizeSubviews:(UIView *)view {
CGRect frame = view.frame;
frame.origin.x = frame.origin.x / 320.0f * kScreenWidth;
frame.origin.y = frame.origin.y / 480.0f * kScreenHeight;
frame.size.width = frame.size.width / 320.0f * kScreenWidth;
frame.size.height = frame.size.height / 480.0f * kScreenHeight;
view.frame = frame;
for (UIView *subview in view.subviews) {
[self resizeSubviews:subview];
}
}
Then call that method after adding your subviews with:
[self resizeSubviews:self.view];
There are a lot of ways this could not work, but it covered me during the switch from iPhone 4s to iPhone 5.
I'm developing an application in iOS8 in landscape mode and everything works fine. I'm using UIKit and don't support portrait mode at all.
Im trying to customise it to iOS7 but the frame that I'm getting is always like the iPhone is in a portrait mode.
I know that the in iOS8 there was a major change with the width and height and it's different in iOS7.
I have the following method which I used to set the window n the appDelegate and when I need the frame at the ViewControllers.
I'm doing the following:
- (CGRect) screenRect {
CGRect screenRect = [UIScreen mainScreen].bounds;
if ((NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_7_1) && UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) {
return CGRectMake(0,0,screenRect.size.height, screenRect.size.width);
}
return screenRect;
}
The views look fine but the left/right side of the screen (depends on the device orientation) behaves like it's outside the frame. i.e doesn't response to gestures!
When I'm setting the fame to the new "screenRect" it keeps turning back to the device bounds.
Thank you very much.
I try to make my Views completely dynamic so the Views can fit any Screen Dimensions. At the Moment i get the screen Width and Height for calculation like this:
CGFloat getDisplayHeight() {
CGSize result = [[UIScreen mainScreen] bounds].size;
return result.height;
}
CGFloat getDisplayWidth() {
CGSize result = [[UIScreen mainScreen] bounds].size;
return result.width;
}
The Problem is that the "Resizable Iphone" Emulator always give me a Width of 768 and a Height of 1024 (Like the iPad). It doesn´t matter when i change the Width and Height Values on the Bottom of the Emulator...is there any new Function i can use for better testing?
EDIT:
I´m still not sure how to handle this exactly...At the Moment i calculate the Size of my Subviews in "viewDidLayoutSubviews" because this is the only Method which shows the correct Width and Heigth of the "resizable Iphone Simulator", the Problem is that when i calculate all my Stuff inside this method it gets called every time when i scroll or touch the UI, so it could be the case that it gets called hundreds of times...and when i try to calculate my Views in "ViewDidAppear" its too late and evrything look reallys weird after the recalculation....
I have written an Augmented reality app for iOS which uses location services and GPS, everything works fine when the device is in landscape left but when the devices rotation is landscape right the center azimuth does not get calculated correctly, I am currently calculating this using the true heading in the didUpdateHeading method the subtracting a heading adjustment of 90 degrees. Should I be checking if < 0??
Thanks.
This is a pretty annoying issue and it seems that setting the headingOrientation property doesn't actually do anything.
The code below works for a landscape left orientation (home button on the right):
orientation = (float) manager.heading.magneticHeading;
orientation += 90.0f;
if(orientation > 360.0f)
orientation -= 360.0f;
So for a landscape right orientation, this should do the trick:
orientation = (float) manager.heading.magneticHeading;
orientation -= 90.0f;
if(orientation < 0.0f)
orientation += 360.0f;
This are getting me a little confuse. I know the 2 properties in UIScreen about the size screen, like in this question use applicationFrame, and this uses bounds.
applicationFrame - Show the size of device minus the statusBar. Making a NSLog in a iPhone, i get this values: (x=0, y=20, height= 460, width = 320)
bounds - Show all size screen. The values is: (x=0, y=0, height=480, width=320)
Now, if I rotate the device (potrait to ladscape) this will show
(The bounds will be all the same value)
Go to function: shouldAutorotateToInterfaceOrientation: x= 0 y=20 height= 460 width= 320
return YES so
Go function: didRotateFromInterfaceOrientation: x= 20 y=0 height= 480 width= 300
I don't know why, but this pass one more time in shouldAutorotateToInterfaceOrientation and show: x= 20 y=0 height= 480 width= 300 (Is this a bug?)
I want to resize my view to this new size, but if I get the CGRect, it will give the correct size in the didRotateFromInterfaceOrientation and the height will be width and vice-versa.
Are there a good way to beautiful resize my view without setting this values by hand?
(Assuming this point was for rotating from landscape back to portrait)
I don't know why, but this pass one
more time in
shouldAutorotateToInterfaceOrientation
and show: x= 20 y=0 height= 480 width=
300 (Is this a bug?)
Its not a bug!
shouldAutorotateToInterfaceOrientation is called before the UI rotates to match the orientation of the device. So, in the first case (Portrait to Landscape) it gives you the rect for the portrait orientation. in the second case (Landscape to Portrait) it gives you the rect for the Landscape orientation.
Bottomline:
shouldAutorotateToInterfaceOrientation gives CGRect values before initiating the UI rotation
didRotateFromInterfaceOrientation gives CGRect values after completing the UI rotation
I suggest you look autoresizesSubviews and autoresizingMask properties of UIView. This saves a lot of headaches when you are working with views that have to rotate/resize.
Hope I have answered your question and you find this useful!