Actionsheet on ipad

↘锁芯ラ 提交于 2019-12-06 08:50:35

问题


This code works fine on iPhone, but on iPad the actionsheet is showing up in the middle of screen. not in the corner where the trigger button is. Also there is no cancel buttons showing up.

Also, the app is only in landscape mode. The camera trigger button is on top right corner of the screen.

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

I need actionsheet to show up where the button is. How should I go about it.


回答1:


IPAD have some special rules about actionsheets and their cancel buttons, it usually depends on where you are displaying the actionsheets from

You can show an action sheet from a UIToolbar, UITabBar,UIBarButtonItem, or from a UIView. This class takes the starting view and current platform into account when determining how to present the action sheet. For applications running on iPhone and iPod touch devices, the action sheet typically slides up from the bottom of the window that owns the view. For applications running on iPad devices, the action sheet is typically displayed in a popover that is anchored to the starting view in an appropriate way. Taps outside of the popover automatically dismiss the action sheet, as do taps within any custom buttons. You can also dismiss it programmatically.

When showing an action sheet on iPad, there are times when you should not include a cancel button. If you are presenting just the action sheet, the system displays the action sheet inside a popover without using an animation. Because taps outside the popover dismiss the action sheet without selecting an item, this results in a default way to cancel the sheet. Including a cancel button would therefore only cause confusion. However, if you have an existing popover and are displaying an action sheet on top of other content using an animation, a cancel button is still appropriate

instead of using showInView try using from one of these method

[actionSheet showFromBarButtonItem:barItem animated:YES];

Explaination is here & here




回答2:


On the iPad, don't use showInView:. Instead, use one of the other more specific methods for showing the action sheet such as showFromBarButtonItem:animated:.

As noted in nsgulliver's answer, it is normal for action sheets to not display the Cancel button on an iPad. All the user needs to do is tap outside the action sheet. This is treated the same as canceling.



来源:https://stackoverflow.com/questions/15098660/actionsheet-on-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!