UIActionSheet Change arrow position?

旧城冷巷雨未停 提交于 2019-12-09 07:47:57

问题


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?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/3763324/uiactionsheet-change-arrow-position

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