UIActionSheet centralisation on rotation
Asked Answered
B

1

34

A number of others have asked this question, but it's never been answered. The problem seems trivial and yet it hasn't been addressed in Apple's documentation or elsewhere.

I'm presenting my UIActionSheet instance using the showInView method:

    UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:@"Test" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Destroy" otherButtonTitles:@"One", @"Two", nil];

    [myActionSheet showInView:self.view];

The UIActionSheet is rendered in the center in whichever orientation it is launched, but when I rotate the iPad, it is seen in the top-right or the bottom-left (depending on whether the orientation changed to Portrait or Landscape).

This behavior is what one would expect if the Autoresizing Masks were set to UIViewAutoresizingFlexibleBottomMargin and UIViewAutoresizingFlexibleRightMargin, which is the default autoresizingMask value for most view elements, so I tried resetting the value by calling the setAutoresizingMask method on the UIActionSheet instance.

[myActionSheet setAutoresizingMask:UIViewAutoresizingNone];

But neither this nor any other value for the Autoresizing Mask achieves any change whatsoever.

Is there any solution to this problem? I would prefer not resorting to dismissing the UIActionSheet on rotation and re-displaying it - that approach seems unnecessary in principle.

Bulahbulawayo answered 2/4, 2013 at 12:12 Comment(0)
S
0

UIActionSheet is a UIView subclass, so you can set the frame of it if you want. I just tested it and setting the frame has the desired effect.

Scaife answered 4/11, 2022 at 18:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.