iPad launch in landscape issue - objective-c

When I'm in landscape mode on iPad and trying to launch app I'm getting strange behavior:
My root view controller view is created with dimensionality equal to 768x1024 whereas it should be 1024x768 (device is in landscape mode). Because of that my view hierarchy is corrupted.
View is created by the system (I'm using nib for interface).
Does it bug in iOS, or, maybe, I'm doing something wrong?
Edit: Autoresizing mask is default (everything resizes).

Found a solution here Reporting incorrect bounds in landscape Mode.
I was checking view controller view size in viewDidLoad, while correct sizes available only in viewDidAppear.

That is ok. It is always creates views in portrait orientation when perform rotation to lanscape. So U should implement
- (BOOL) shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)
And check in code

Related

Need a way to force a UIInterfaceOrientation rotation without iOS device rotating

I need to know if there is a way to tell a iOS7 device to set a views orientation without the device being rotated. Some way in code to trigger the device to calling the code that tells it which way to display the view.
If the device is in landscape and remains held in landscape orientation while a certain change happens I want to force a change to show the view in portrait orientation, at which point the user would need to turn the device to look at it properly. I'll explain why below
Looking at my app might make my description clearer - it is free to download
I have a number of view controllers (embedded in navigationControllers) and only one of them needs to be rotated into landscape and then only under certain conditions.
Solutions here on StackOverflow seem to be to make a category on UINavigationController giving it shouldAutorotate and supportedInterfaceOrientations methods and then use those methods in the individual viewControllers to block or allow rotations.
This has worked for me .... however
On the one view controller I wish to rotate , I don't want it to rotate all the time.
This view controller is the diveSiteDetailsController, (if you have downloaded the app you need to select dive sites on the first page then click the '+' to see it). It has a UISegmentedController and 4 subviews (3 tableviews and 1 other UIView). The current version on the App Store works fine now i've solved this - but looking at it may help you understand my issue better).
On diveSiteDetailViewController the UISegmentedController is used to switch between the 4 subviews.
All the subviews are used to enter data about the same dive site but as there is a lot of potential data, I have broken it into logical chucks each of which is a subview - location, data (depths,currents, visibility), type of environment and notes.
The .hidden property of each subview is used to make them appear and disappear.
I only want the second subview to rotate (the data view - it has some sliders on it that are easier to work with if in landscape).
restricting this rotation is easy - iI achieved it like this
- (NSUInteger)supportedInterfaceOrientations{
if (self.dsDataRangeSlidingTV.hidden) {
return UIInterfaceOrientationMaskPortrait;
}
return UIInterfaceOrientationMaskAllButUpsideDown;
}
Now the view will only rotate to landscape when the data table view is displayed.
However, once in landscape, if I chose a different subview with the UISegmentedController then they are, obviously, shown in landscape also as the iOS device hasn't done a rotation. This is the situation I am trying to avoid.
Rotating the iOS device will return those views to portrait as expected but i need to trigger the device to to reevaluate its display when I use the UISegmentedController to switch from the data subview to another subview and its that triggering that I don't know how to do.
any suggestions greatly received.
Heres a workaround that is working for me
I've added the following few lines to the end of my method that responds to the UISegmentedControl being tapped.
UIViewController *aDummyController = [[UIViewController alloc]init];
[self presentViewController:aDummyController animated:NO completion:nil];
[self dismissViewControllerAnimated:NO completion:nil];
adding a new viewController and popping it off triggers the rotation . This is a kludgey way of achieving what I wanted.
I found the solution in this post
Is there a documented way to set the iPhone orientation?
all credit to Josh who although not the accepted answer is the one that 99 people currently have up voted.
I still have a bug in that, if I were holding the device in landscape (although the display is portrait view) whilst on the screen that segues into the diveSiteDetailsController then the initial view the diveSiteDetailsController display will be in landscape.
To get around this I created a Bool property called notThisTime on the diveSiteDetailsController and set it to true in the prepareFor Segue on the viewController that called it.
i then did changed supportedInterfaceOrientation to
- (NSUInteger)supportedInterfaceOrientations
{// DLog(#"Running %# '%#'", self.class, NSStringFromSelector(_cmd));
if (self.notThisTime){
return UIInterfaceOrientationMaskPortrait;
}
if (!self.dsDataRangeSlidingTV.hidden) {
return UIInterfaceOrientationMaskAllButUpsideDown;
}
then at the end of the ViewDidLoad method I added
self.notThisTime = NO;
I would still love to hear from anyone with a suggestion how better to handle this. pushing and popping a dummy view to get the iPhone to do an orientation check seems like a work around for something that should just be available as a standard method call.
One final Note - the iOS simulator does not like this - you need to check on the device - it sometimes tries to draw the iPhone container in landscape while the screen is drawn vertically - however it does work fine on the iPhone

Autorotation in ios 5 vs. ios 6 issues

I have an iPad app that must support iOS 5.0 and later. I have a bug that behaves differently in 5.0/5.1 than it does in 6.0. The issue is a view controller in a tabbarcontroller that pushes a modal view, which in turn pushes a full-screen view via navigationController. The problem is, when in the full-screen view, if the iPad is rotated, the underlying viewcontroller (one in the tabbarcontroller) doesn't rotate. Now let me break down the differences in iOS versions:
First of all, this viewController in question implements shouldAutoRotateToInterfaceOrientation (returns YES) as well as willRotateToInterfaceOrientation and willAnimateRotationToInterfaceOrientation.
In iOS 6.0, I noticed that the rotation methods (willRotate... & willAnimate...) were not being called, so I registered it to receive the UIDeviceOrientationDidChangeNotification notification and execute the code from the two Rotate methods if I received that notification and the other methods hadn't executed. That fixed the issue in iOS 6.0.
Problem is, in 5.0/5.1 the rotation methods (willRotate... & willAnimate...) ARE being executed, but the view is not rotating. If the "full-screen view" is not presented over top of this view controller and the iPad is rotated, these two methods execute and the views rotate accordingly.
Please help. Thanks in advance.
Things I've tried other than that stated above.
I've tried checking the UIDeviceOrientation and converting it to a UIInterfaceOrientation and calling [self shouldAutorotateToInterfaceOrientation:xxx]; The view still displays wrong.
When the two rotation methods are being executed, do the CAAffineTransformation for your view. when you are back to normal, again do the same with -90 degree.
https://developer.apple.com/library/ios/#documentation/GraphicsImaging/Reference/CGAffineTransform/Reference/reference.html

Application Lauch in Landscape mode while Simulator/Device is in Portrait mode in ios6

My application window has UITabBarController as a RootViewController. Then UINavigationController as TabBarController's RootViewController. Then another HomeViewController as NavigationController's RootViewController.
When I launch my application in Portrait mode, then HomeViewController's UIView outlets displayed in Landscape mode. All UIView outlets have Landscape mode coordinate. Because return Orientation is Landscape.
I found many Q&A, Blogs. I applied whatever other developers said, but not succeed.
This issue occurs only in ios6 device/iPhone simulator 6.
Right now I am working on Simulator and its show this issue.
Please help me as soon as possible.
Ask me, if I am not capable to explain my question.
Thank you in advance.
In iOS 6, the app looks at your predefined possible orientations from your project file. Check if that only lists landscape, also it uses the shouldAutoRotate method, so you might have to implement that as well.
Check this for more info:
Similar question

Landscape mode for a viewController in a UITabBarController

I have some 10 view controllers contained in a TabBarController. We have a requirement wherein one view controller out of these 10 view controllers should always be displayed in landscape mode.
Now, when we override:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
and return YES only for Landscape mode in such view controllers, it has not effect. The view controller appears in Portrait mode only.
Probably this is done for a good reason, since when the user switches to a tab whose view controller should support only landscape mode, the whole screen components (including the tabbar) should be rotated to landscape mode, which looks awkward.
Am I right in assuming the cause?
Also, what would be the best way to tackle this? Provide an intermediate view controller in portrait mode and then push the landscape view controllers through it?
Thanks,
Raj

How do I rotate the contents of a UIWebView?

I have made a very simple web browser app using a web view. Now I need to get the app so that when the iPhone is rotated, the text of the page is rotated as well.
How do I do this?
I am very confused by the auto-resize dialog, so it is possible I have done something wrong there.
Any help would be appreciated!
I think you sholud rotate UIWebView widget, not its contents. Contents should rotate as well. To support rotating add following code to your view controller:
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Rotated widget might look different then expected. Adjust struts and springs in Interface Builder.
I think you need to give us some sample code in order to determine what goes wrong. It is as Jacek says, the only think you should need to do is to support auto rotation on the UIWebView itself. The content should be rotated automatically.
I think you are confused by device orientation and view frame.
In most cases UIViews do change with respect to the orientation change. But to clarify - it is not because of the orientation change, but the layout change.
Only UIViewControllers need to consider device orientation - UIViews do NOT. When the device orientation changes, the UIViewController captures the event from its instance methods:
– willRotateToInterfaceOrientation:duration:
– willAnimateRotationToInterfaceOrientation:duration:
– didRotateFromInterfaceOrientation:
The UIViewController then re-layout the views - leading to reframing of the UIViews. In many cases, iOS can helps you in simplifying the relayout process by setting the UIViewAutoresizeMask. For example:
myWebview.autoresizeMask = UIVIewAutoresizeMaskFlexibleHeight | UIVIewAutoresizeMaskFlexibleHeight;
implies that when webview's superview changed its bounds, the webview will change accordingly.
As a summary, UIView only takes care of its frame / bounds etc.