开发者

UIActionSheet won't display properly in landscape mode

开发者 https://www.devze.com 2023-01-16 00:26 出处:网络
I am trying to display a UIActionsheet in my application.It works perfectly in portrait mode but when I try to have it display in a landscape orientation it still slides in from the bottom.However it

I am trying to display a UIActionsheet in my application. It works perfectly in portrait mode but when I try to have it display in a landscape orientation it still slides in from the bottom. However it no longer uses buttons and displays with the picker control like it is in landscape mode. Its just in the wrong position.

I don't use auto rotation and keep everything in portrait mode. Occasionally I am displaying things in a landscape mode and would like the actionsheet to appear properly.

I am setting the status bar orientation like so...

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];

When I'm in 'landscape mode', and the status bar always appears correctly. If i display an AlertView it also displays correctly. I am then displaying the actionsheet like this

UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel Button" destructiveButtonTitle:nil otherButtonTitles: @"button", nil];    
as.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[as showInView:self.view];
//[as showFromToolbar:toolbar];

I have also tried to display it from the app delegate and toolbar. If I set the statusbar orientation just before displaying it still doesn't work. I have even tried.

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];

Does anyone has any idea why the actionsheet could be displaying in the wrong position yet with the right controls? Or how to force the actionsheet to display in a particular position. I would rather not have to implement my own version of an actionsheet to have it display right.

Thanks in advance.

Edit / Solution: Force Action sheet to show in landscape mode

Here is how i managed to get it to work, i created a landscape view and added it to my main window like so:

landscapeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 480, 480)];
landscapeV开发者_如何学JAVAiew.transform = CGAffineTransformMakeRotation((-1)*M_PI/2);
landscapeView.bounds = CGRectMake(0, 0, 480, 380);
[appDelegate.window addSubview:landscapeView];

and then displayed my action sheet like this

if (landscape) {
    [menu showInView:landscapeView];
} else {
    [menu showInView:self.view];
}

Much thanks to tc. for pointing me in the right direction here.


I had a similar issue. I had a button in my toolbar that displayed an action sheet. The code to display the Action Sheet was in my rootViewController. It displayed incorrectly in landscape mode with this code:

[actionSheet showInView:[self.view]];

This change corrected the issue:

[actionSheet showInView:[self.navigationController view] ];

It seems like the ActionSheet gets it's orientation from the view passed into ShowInView and my rootViewController was in Portrait mode even though my current view was in Landscape. At least, that's my theory.


The overall "interface orientation" also encompasses things like the current view transform, whatever UIViewController thinks is the current orientation, and probably other stuff too; just setting the status bar orientation is not always sufficient.

Is self.view in portrait orientation?

0

精彩评论

暂无评论...
验证码 换一张
取 消