编辑:我在这里整理了一个更完整的解决方案https://github.com/brandonschlenker/BSActionSheet
这有点痛苦,老实说,我不确定这是否值得。如果 Apple 更改 UIActionSheet,所有这些都可能会中断。无论如何,这可能是一个解决方案......
您将需要继承 UIActionSheet 并根据其调整所有子视图和超级视图的大小。
在布局子视图中,我们将遍历视图并开始调整元素的大小以满足我们的需求。我首先注销了子视图列表以查找哪个元素是哪个元素。到目前为止,我已经找到了表格视图、圆角的表格视图框架、弹出框等。您仍然需要找到取消按钮并移动它。
- (void)layoutSubviews
{
CGRect tableViewFrame = CGRectZero;
for (id item in [self subviews])
{
if ([item isKindOfClass:[UIView class]])
{
UIView *v = (UIView *)item;
v.frame = CGRectMake(v.frame.origin.x, v.frame.origin.y, self.frame.size.width, 320);
for (UIView *subItem in [v subviews])
{
//table view of options
if ([subItem isKindOfClass:[UITableView class]])
{
subItem.frame = CGRectMake(subItem.frame.origin.x, subItem.frame.origin.y, subItem.frame.size.width, someNewHeightHere);
tableViewFrame = subItem.frame;
}
//table view image frame. this rounds the bottom corners
if ([subItem isKindOfClass:[UIView class]] && subItem.tag == 3334)
{
subItem.frame = CGRectMake(subItem.frame.origin.x, tableViewFrame.origin.y, subItem.frame.size.width, someNewHeightHere);
}
//this is the cancel buttons label. never could get this to do anything
if ([subItem isKindOfClass:NSClassFromString(@"UIButtonLabel")])
{
if (subItem.frame.size.width == 66)
{
}
}
}
}
}
UIViewController *v = [self viewController];
v.contentSizeForViewInPopover = CGSizeMake(self.frame.size.width, someNewHeightHere);
}
我还有一个方便的方法来获取视图父视图控制器。
- (UIViewController *)viewController
{
UIResponder *responder = self;
while (![responder isKindOfClass:[UIViewController class]]) {
responder = [responder nextResponder];
if (nil == responder) {
break;
}
}
return (UIViewController *)responder;
}