在ipad上的动作表

Cal*_*one 3 alignment uiactionsheet ipad ios

此代码在iPhone上运行良好,但在iPad上,操作表显示在屏幕中间.不在触发按钮所在的角落.此外,没有取消按钮显示.

此外,该应用程序仅处于横向模式.相机触发按钮位于屏幕的右上角.

mediaPicker = [[UIImagePickerController alloc] init];
mediaPicker.allowsEditing = YES;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:self
                                                    cancelButtonTitle:@"Cancel"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"Take photo", @"Choose Existing", nil];
    //[actionSheet showInView:self.view];
    [actionSheet showInView:self.navigationController.view];
}
// If device doesn't has a camera, Only "Choose Existing" and "Cancel" options will show up.
else {
    UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                             delegate:self
                                                    cancelButtonTitle:@"Cancel"
                                               destructiveButtonTitle:nil
                                                    otherButtonTitles:@"Choose Existing", nil];
    [actionSheet showInView:self.view];
}
Run Code Online (Sandbox Code Playgroud)

我需要动作表来显示按钮的位置.我应该怎么做呢.

nsg*_*ver 8

IPAD有一些关于actionsheets及其取消按钮的特殊规则,它通常取决于您显示actionsheets来自哪里

您可以从显示的动作片UIToolbar,UITabBar,UIBarButtonItem,或从UIView.在确定如何呈现操作表时,此类将起始视图和当前平台考虑在内.对于在iPhone和iPod touch设备上运行的应用程序,操作表通常从拥有视图的窗口底部向上滑动.对于在iPad设备上运行的应用程序,操作表通常显示在以适当方式锚定到起始视图的弹出窗口中.弹出窗口外的点击会自动关闭操作表,任何自定义按钮内的点击都会自动关闭.您也可以通过编程方式解除它.

在iPad上显示操作表时,有时您不应包含取消按钮.如果仅显示操作表,系统将在不使用动画的情况下在弹出框中显示操作表.由于弹出窗口外的水龙头在不选择项目的情况下关闭操作表,因此这将导致取消工作表的默认方式.因此,包括取消按钮只会引起混淆.但是,如果您有一个现有的弹出窗口并且正在使用动画在其他内容上显示一个操作表,则取消按钮仍然是合适的

而不是使用showInView尝试使用这些方法之一

[actionSheet showFromBarButtonItem:barItem animated:YES];
Run Code Online (Sandbox Code Playgroud)

解释就在这里这里