UIActionSheet will not display correctly in landscape mode

I am trying to display a UIA table in my application. It works fine in portrait mode, but when I try to display it in landscape orientation, it still slides from below. However, it no longer uses buttons and displays with selection controls, as in landscape mode. He is in the wrong position.

I do not use automatic rotation and save everything in portrait mode. Sometimes I show things in landscape mode and want the worksheet to display correctly.

I set the status bar orientation like this:

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

When I am in "landscape mode" and the status bar is always displayed correctly. If I display an AlertView, it will also display correctly. Then I show an action table 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 also tried displaying it from the application delegate and toolbar. If I set the orientation of the status bar immediately before displaying it, it still doesn't work. I even tried it.

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];

Does anyone know why the action sheet might appear in the wrong position, but with the right controls? Or how to make the action table display in a specific position. I would prefer not to use my own version of the action sheet so that it displays correctly.

Thanks in advance.

Edit / Decision: Force action sheet to display 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:

landscapeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 480, 480)];
landscapeView.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];
}

Thanks a lot tc. to point me in the right direction.

+3
2

" " , , , UIViewController, - , , ; .

self.view ?

+2

. , . . :

[actionSheet showInView:[self.view]];

:

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

, ActionSheet , ShowInView, rootViewController Portrait, Landscape. , .

+13

Source: https://habr.com/ru/post/1764336/


All Articles