alexbw
alexbw

Reputation: 2038

Force autoresizingMask to apply to a UIView

I have a notification view which I'm adding to the application's window after launch, so it hovers above all other views.

When the user rotates the device, the view does not autoresize like those owned by a UIViewController.

Is there a way to manually ask for the view's autoresizingMask to be applied? Or, alternatively, how can I have a view with no view controller be resized on device rotation?

Upvotes: 3

Views: 1893

Answers (3)

Cowirrie
Cowirrie

Reputation: 7226

I found that views added to the application window don't even rotate, let alone resize.

This was asked and answered for Orientation in a UIView added to a UIWindow: add the notification view to the first subview of the window.

UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window) 
    window = [[UIApplication sharedApplication].windows objectAtIndex:0];
[[[window subviews] objectAtIndex:0] addSubview:myView];

And, it also solves your problem, your notification view should now be resized in accordance with its masks.

Upvotes: 1

hotpaw2
hotpaw2

Reputation: 70673

Did you set:

view.autoresizesSubviews = YES;

in the appropriate superview?

Upvotes: 0

Brian
Brian

Reputation: 15706

autoResizingMask doesn't have anything to do with rotation per se. It just defines how the view should be sized when its superview is resized.

It should work if you add a top-level view controller, with a view the same size as the window and which contains all other views. Then your notification view will be a subview of the toplevel view (connected to a view controller), and should autorotate.

Upvotes: 0

Related Questions