Issue with UIActionSheet

2020-02-20 06:35发布

问题:

When I run my app and I click button for actionsheet appears this:

Presenting action sheet clipped by its superview. Some controls might not respond to touches. On iPhone try -[UIActionSheet showFromTabBar:] or -[UIActionSheet showFromToolbar:] instead of -[UIActionSheet showInView:].

How can I fix?

回答1:

Try this, it worked for me perfectly:

[actionSheet showInView:[UIApplication sharedApplication].keyWindow];


回答2:

You could try [MyActionSheet showInView:super.view]; or if you have a UITabBar or UIToolbar then, as it suggests, you can use [MyActionSheet showFromTabBar:self.tabBarController.tabBar]; or [MyActionSheet showFromToolBar:self.toolbar];



回答3:

It should be resolved to use [actionSheet showInView:self.parentViewController.view]; instead of self.view if you are using UINavigationViewController because this controller has top navigation bar as default.



回答4:

    [sheet showInView:[UIApplication sharedApplication].keyWindow];
    sheet.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height-sheet.frame.size.height, [UIScreen mainScreen].bounds.size.width, sheet.frame.size.height);

This should solve the problem.



回答5:

I resolved my nearly-the-same case by:

YourAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
[actionSheet showFromTabBar:delegate.tabBarController.tabBar];

assume you use TabBarController xCode template as a start.



回答6:

Remember that your toolbar may be part of your navigation controller. You can access it with self.navigationController.toolbar



回答7:

Another similar solution, which worked for me with a UIPageViewController -> UINavigationViewController -> TableViewController structure, is:

[actionSheet showInView:self.view.superview];


回答8:

Use this:

[actionSheet showInView:self.view.window];

This will force the action sheet to be displayed above navigation bars and respond to all taps. Note however that if you use some left/right sliding menu libraries, this may result in the actionSheet to be presented off screen. Just test...



回答9:

I tried all of the above answers to no avail. Ultimately, I found that the only solution was to reduce the number of items on the action sheet, which was overflowing.



回答10:

Heres the Swift version:

actionSheet.showInView(UIApplication.sharedApplication().keyWindow)