Xcode中iPad的UIActionSheet带有许多按钮,在iOS7上无法正确显示。

15

iPad上的新iOS 7 UIActionSheet在有大量按钮时无法正确显示。

在滚动时未清除UIActionSheet的背景。按钮似乎被冻结在背景UIActionSheet中。

问题截图

我的代码:

UIActionSheet *popupQuery = [[UIActionSheet alloc]; 
for (int i=0; i<[ParamAllList count]; i++) 
{ 
    NSMutableDictionary *Param = [ParamAllList objectAtIndex:i]; 
    [popupQuery addButtonWithTitle:[Param valueForKey:@"name"]]; 
    [[[popupQuery valueForKey:@"_buttons"] objectAtIndex:[[popupQuery valueForKey:@"_buttons"] count]-1] setImage:[UIImage imageNamed:@"add40icon.png"] forState:UIControlStateNormal];
} 
popupQuery.actionSheetStyle = UIActionSheetStyleAutomatic; 
[popupQuery showFromRect:Button_Settings.frame inView:Button_Settings.superview animated:YES];

请在创建UIActionSheet时添加代码。 - Jordan Montel
UIActionSheet *popupQuery = [[UIActionSheet alloc]; for (int i=0; i<[ParamAllList count]; i++) { NSMutableDictionary *Param = [ParamAllList objectAtIndex:i]; [popupQuery addButtonWithTitle:[Param valueForKey:@"name"]]; [[[popupQuery valueForKey:@"_buttons"] objectAtIndex:[[popupQuery valueForKey:@"_buttons"] count]-1] setImage:[UIImage imageNamed:@"add40icon.png"] forState:UIControlStateNormal]; } popupQuery.actionSheetStyle = UIActionSheetStyleAutomatic; [popupQuery showFromRect:Button_Settings.frame inView:Button_Settings.superview animated:YES]; - Constantinus
我基本上在做同样的事情,没有图片:即使我这样做:UIActionSheet *popupQuery = [[UIActionSheet alloc] initWithTitle:@"test" delegate:self cancelButtonTitle:@"" destructiveButtonTitle:@"Cancel" otherButtonTitles:@"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi", @"hi",nil]; 它会出现问题...与按钮数量有关。 - dan
当按钮数量适合不需要滚动时 - 一切正常。 当有滚动按钮时 - 背景会变暗。 遍历UIActionSheet的子视图后,发现UIActionSheet对象仅包含标签和按钮(没有tableView或scrollView)- 因此出现了这个bug。 - Constantinus
你为此提交了雷达反馈吗? - Ryan Poolos
我为此问题提交了rdar://15828155,并验证它在最新的iOS 7.1 beta 3版本中仍未修复。 - Ryan Poolos
2个回答

24

这是我针对 actionSheet 委托的解决方法:

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
    actionSheet.backgroundColor = [UIColor whiteColor];
    for (UIView *subview in actionSheet.subviews) {
        subview.backgroundColor = [UIColor whiteColor];
    }
}

基于这个答案:更改UIActionSheet按钮中的文本颜色


2
-(void)willPresentActionSheet:(UIActionSheet *)actionSheet{ int count=0; for (UIView *object in actionSheet.subviews) { if ([[[object class] description] isEqualToString:@"UIView"]) { count++; if (count==2) { object.backgroundColor = [UIColor whiteColor]; break; } } } } - Constantinus
谢谢))))))我的代码会留下一点透明的背景。 - Constantinus
2
不错的解决方案,可惜存在这样的问题。谢谢。 - mashdup

2
有趣的事情 - 这个漏洞仍然存在于iOS 7.1beta4中 :)
而且只出现在iPad实现中,而不是iPhone...
它的起源非常奇怪 - 当一个UIActionSheet有很多项时,“模糊”效果会显示出来,因此它必须将这些项放在类似于UITableView的容器中,但不幸的是,这个视图容器被放了两次(并且不是同一个实例)。 因此,我们需要只留下一个并删除其他的。
另一件需要纠正的事情是UITableView的高度。
以下是我的修复方法 - 实现在UIActionSheetDelegate -(void)willPresentActionSheet:
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

- (void)willPresentActionSheet:(UIActionSheet *)actionSheet {
    if( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0") ) {
        if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
            // fix for iOS7 iPad UIActionSheet presentation when content need to scroll
            // and scrolled view appears with unnecessary copies, remove not needed ones
            // and set proper tableview height too
            int count = 0;
            for (UIView *subview in actionSheet.subviews) {
                if( [subview isMemberOfClass:[UIView class]] ) {
                    if( ++count == 1 ) {
                        // process only first view
                        for( UIView *subsubview in subview.subviews ) {
                            if( [subsubview isKindOfClass:[UITableView class]] ) {
                                // fix table view height
                                UITableView *tableView = (UITableView*)subsubview;

                                CGRect tableViewFrame = tableView.frame;
                                tableViewFrame.size.height -= subview.frame.origin.y;

                                tableView.frame = tableViewFrame;
                            }
                        }
                    } else {
                        // remove unnecessary view
                        [subview removeFromSuperview];
                    }
                }
            }
        }
    }
}

对我来说不起作用(iOS 7.1),结果只是一个模糊的白色背景(没有tableView)。 - osxdirk

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接