iPad上的工作表

此代码在iPhone上正常工作,但在iPad上,操作表显示在屏幕中间。 不在触发button所在的angular落。 也没有取消button显示。

此外,该应用程序只在横向模式。 相机触发button位于屏幕的右上angular。

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]; } 

我需要动作表来显示button的位置。 我应该如何去做。

IPAD有一些关于actionsheets和取消button的特殊规则,通常取决于你在哪里显示actionsheets

您可以从UIToolbarUITabBarUIBarButtonItemUIView显示一个操作表。 在决定如何呈现操作表时,这个类将考虑起始视图和当前平台。 对于在iPhone和iPod touch设备上运行的应用程序,操作表通常从拥有该视图的窗口底部向上滑动。 对于在iPad设备上运行的应用程序,操作表通常以适当方式锚定到起始视图的popup窗口中显示 。 popup窗口之外的窗口会自动closures操作页面,就像在任何自定义button中点击一样。 您也可以以编程方式closures它。

在iPad上显示动作表时,有时候不应该包含取消button。 如果您只展示操作表,则系统将在不使用animation的情况下在popup窗口中显示操作表。 由于popup窗口以外的点击会在不select项目的情况下closures操作页面,因此会导致取消页面的默认方式。 包括一个取消button,只会造成混乱。 但是,如果您有一个现有的popup窗口,并使用animation在其他内容的顶部显示一个操作表,则取消button仍然适用

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

 [actionSheet showFromBarButtonItem:barItem animated:YES]; 

解释是在这里 & 这里

在iPad上,请勿使用showInView: 相反,使用其他更具体的方法之一来显示操作表,如showFromBarButtonItem:animated:

正如nsgulliver的回答所指出的那样,操作表不能在iPad上显示“取消”button是正常的。 所有用户需要做的就是点击操作表外部。 这和取消一样。