UIActionSheet 弹出时箭头

来源:互联网 发布:android源码 小米商城 编辑:程序博客网 时间:2024/04/30 12:05
1.调整ipad上UIActionSheet的arrow方向
ipad上面UIActionSheet可以有箭头,但其方向不能像popover那样调整,上面查资料有如下解决方法:
参考:http://stackoverflow.com/questions/3763324/uiactionsheet-change-arrow-position

重要的就是这两句:
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, butif 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. 

2.应用
工作中遇到编辑头像,图片来源:camera,album两种,在Iphone上面没有问题,但在Ipad上由于上面区别就有问题了
先弹UIActionSheet,但弹出来的总是箭头向下的,我想弹个箭头向上,以便切换成Popover时在同一位置

初始代码:

[cpp] view plaincopy
  1. UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"camera" otherButtonTitles:nil];  
  2.     [sheet addButtonWithTitle:@"album"];  
  3.     // avaterBtn bounds:(0,0,80,80)  
  4.     [sheet showFromRect:CGRectMake(0, 0, 80, 80) inView:avaterBtn animated:YES];  
  5.     [sheet release];  


改为:

[cpp] view plaincopy
  1. UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"camera" otherButtonTitles:nil];  
  2.     [sheet addButtonWithTitle:@"album"];  
  3.     [sheet showFromRect:CGRectMake(0, -200, 80, 280) inView:avaterBtn animated:YES];  
  4.     [sheet release];  


从事Ios开发快一年了,以后遇到问题时不能网上搜搜解决就行,一定要深入了解其原理