UIActionSheet Change arrow position?

2019-03-23 10:45发布

To show a UIActionSheet on the iPad I did this:

[actionSheetX showFromRect:RectX inView:myView animated:YES];

The arrow of the popover points down, can I change this position to point left, up or right, like when using a normal popover?

3条回答
在下西门庆
2楼-- · 2019-03-23 10:59
CGRect cellRect = cell.bounds;
cellRect.size.width = cell.frame.size.width * 2;
cellRect.origin.x = -(cell.frame.size.width + 10.0);
[_actionSheet showFromRect:cellRect inView:cell animated:YES];

Thanks to - overboming.

iPad - Split view controller: It displays action sheet with left arrow at end of the master view (table view) cell. Arrow inside with 10 pixels in the cell. Try this. It is easy to understand the logic of action sheet display. Thanks - Manraj.

查看更多
可以哭但决不认输i
3楼-- · 2019-03-23 11:05

Apple doesn't provide any access to internal structure for UIActionSheet's internal implementation of showFromRect, but as for arrow direction, there is actually a very hack-y way to work around this and sort of being able to change arrow direction to a desired direction.

Trick is to mess around the rect parameter in - (void)showFromRect:(CGRect)rect inView (UIView *)view animated:(BOOL)animated. Apple doesn't document this rect parameter very well, but if your original rect will give you a down arrow direction, feed in a rect with a large height and negative number origin.y will kind of push the action sheet popover all the way up thus showing a upward arrow direction. This is a extreme hack but it works consistently across firmware. Hope it helps.

查看更多
时光不老,我们不散
4楼-- · 2019-03-23 11:05

The documentation for the -showFromRect:inView: method states this:

On iPad, this method displays the action sheet in a popover whose arrow points to the specified rectangle of the view

This means that you may be able to get it to display the arrow direction you want by fiddling with the rect. However, there's no reason I can think of why you would want to manually set the arrow direction because UIActionSheet will automatically calculate the best arrow direction.

查看更多
登录 后发表回答