Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Orientation in a UIView added to a UIWindow

I have a UIView which is supposed to cover the whole device (UIWindow) to support an image zoom in/out effect I'm doing using core animation where a user taps a button on a UITableViewCell and I zoom the associated image.

The zooming is performing flawlessly, what I haven't been able to figure out is why the subview is still in portrait mode even though the device is in landscape. An illustration below:

enter image description here

I do have a navigation controller but this view has been added to the UIWindow directly.

like image 211
Ken Avatar asked Mar 24 '10 14:03

Ken


People also ask

What is the difference between Uiwindow and UIView?

So think of a UIView as controlling part of the screen: drawing to it etc. A window is a mere container. The window does cover the entire screen (usually), the window is the root view in the view hierarchy (it is a UIView subclass).

How do you hide Uiwindow?

The correct way to hide a window is to set the hidden property to YES. To remove it from UIApplication's windows property you just release the window (in ARC you set all references to nil). Of course you would want to have another window in place at this time.


2 Answers

You can read about some of the possible causes here:
Technical Q&A QA1688 - Why won't my UIViewController rotate with the device?

In your situation its probably the fact that you are adding the view as another subview to the window. Only the first subview gets the rotation events. What you can do is add it as a subview of the first window subview.

UIWindow* window = [UIApplication sharedApplication].keyWindow; if (!window)      window = [[UIApplication sharedApplication].windows objectAtIndex:0]; [[[window subviews] objectAtIndex:0] addSubview:myView];     
like image 192
dizy Avatar answered Sep 21 '22 15:09

dizy


The problem

Beginning with iOS 6, only the topmost view controller (alongside the UIApplication object) participates in deciding whether to rotate in response to a change of the device's orientation.

https://developer.apple.com/library/content/qa/qa1688/_index.html

The solution

I have open sourced a pod named AGWindowView.
It will automatically deal with any rotation and framechanges so you won't have to worry about that.

The code

It supports any combination of SDK's and iOS system versions. The relevant code can be found here: https://github.com/hfossli/AGWindowView/blob/master/Source/AGWindowView.m

like image 26
hfossli Avatar answered Sep 22 '22 15:09

hfossli