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.
Related
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!
On iOS 9.3 iPhones and iPads (actual devices and in the simulator), I am getting inconsistent information (between the device and the simulator) about the [UIScreen mainScreen].bounds after an orientation change notification.
My view controller adds a notification for orientation changes when the view loads:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:#selector(deviceOrientationDidChangeNotification:)
name:UIDeviceOrientationDidChangeNotification
object:nil];
The behaviour when the orientation changes is as follows:
- (void) deviceOrientationDidChangeNotification:(NSNotification *) notification {
CGRect frame = [UIScreen mainScreen].bounds;
NSLog(#"Main screen is w=%f h=%f", frame.size.width, frame.size.height);
}
Running this on an iPhone, after the orientation changes, the log message indicates a frame width and height that correspond with the post orientation change screen dimensions.
Running this on an iPad, after the orientation changes, the log message indicates a frame width and height that correspond with the pre orientation change screen dimensions.
Is this kind of inconsistency something that needs to be coded around? I could start trying to detect what the orientation is (landscape or portrait) and then using the width and height values that make sense but that is pretty hacky.
The right way to handle this is to avoid the notification system, instead using the
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator
method on the UIViewController where you want to adapt the UI for an orientation change.
Have been looking at the latest version of Core-plot ce0fa44812 and the associated example code.
It supports device orientation, however I am unable to determine the mechanism used to provide this support. I see the orientation options provided in the plist.
In particular I am interested in the Real Time plot example, however see no calls to change the bounds upon rotation from portrait to landscape.
So what magic is going on here? There are the bounds being changed.
That version of the Plot Gallery example app uses a storyboard with the new iOS 8 split view controller to manage all layout and transitions. The views in each storyboard scene use auto layout to resize automatically when needed.
You can change the frame of hostingView when the device rotate.
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator: (id<UIViewControllerTransitionCoordinator>)coordinator {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
} completion:^(id<UIViewControllerTransitionCoordinatorContext> context) {
[self.hostingView setFrame:[self.view bounds]];
}];
[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}
Then you will change to the landscape plot.
If you want to your device is held in portrait before you plot the graph.
You need to set the view controller. Otherwise, there is something like a bug, that the plot is set in portrait size in a landscape mode.
-(void)viewDidLayoutSubviews {
[self.hostingView setFrame:[self.view bounds]];
}
I've worked on the Zbar in iPhone and also in iPad, it works fine without any issues, but not with the landscape mode in iPad. When I present the ZBarReaderViewController in iPad with a popover in landscape mode, the view is 90 degree shifted as in the below image,
where the bag is on the table and the image is captured with iPad in landscape mode. I want the bag image not as shifted.
I've already tried setting the supportedOrientationsMask as
reader.supportedOrientationsMask = ZBarOrientationMask(UIInterfaceOrientationLandscapeLeft || UIInterfaceOrientationLandscapeRight);
But its not showing in the correct orientation, but is a 90 degree shifted. Can someone help me solve this issue? Any timely help is much more appreciated. Thanks.
I had almost the same issue, and I got it resolved by adding the below code. My app supports only Landscape orientation:
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
if (UIDeviceOrientationLandscapeLeft == orientation) {
//Rotate 90
reader.cameraViewTransform = CGAffineTransformMakeRotation (3*M_PI/2.0);
} else if (UIDeviceOrientationLandscapeRight == orientation) {
//Rotate 270
reader.cameraViewTransform = CGAffineTransformMakeRotation (M_PI/2.0);
}
The thing with this solution is that is fixes only the visual part of the problem. The user sees the right orientation, however the ZBarReader still 'sees' the same image, because you're transforming the preview image. What works is this:
[self.readerView willRotateToInterfaceOrientation:[[UIApplication sharedApplication] statusBarOrientation] duration:0];
in the viewDidLoad method of your ViewController containing the ZBarReaderView.
My app is only allowable in the landscape orientations, and it launches in landscape. Thus, the top left corner when the iPad is landscape is (0,0), so everything works fine.
However, when I pick up "touchesBegan"...it isn't working properly. Only when I tap on like the right two-thirds of the iPad does it pick up the touches. I know it has something to do with the orientation, because the app is literally just blank screen with a single UIView and nothing else. It is quite simple. There are no other possible problems that would cause this.
To be sepecific, if I print out the x location in the touchesBegan function, and if the iPad is held with the home button on the left, the width is 1024. And 1024-768 is 256. This is exactly the x position where it begins to sense my touches. Anything to the left of x=256 does not sense the touches.
How do I fix this?
Check Struts and Springs and make sure that whatever should pick up the touches is covering the whole area and locked to the 4 sides.
To do it programmatically,
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
CGRect appFrame = [[UIScreen mainScreen] applicationFrame];
[self.view setFrame:CGRectMake(0.0f, 0.0f, appFrame.size.width, appFrame.size.height)];
return YES;
// if you want to support only LANDSCAPE mode, use the line below
/*
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationLandscapeRight);
*/
}
This sets the view to occupy the full screen.
The answer is that, when defining the UIWindow, it needs to be defined as
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
and not strict coordinates.