UIAlertView按钮框架都是0?

mem*_*ons 2 cocoa-touch uialertview ios4

有没有办法让我在我创建的alertView中获得对按钮框架的引用?我想找到顶部按钮的位置,这样我就可以使用它的框架将图像直接定位在它上面.我在alertview文本的末尾有几个额外的\n,以确保有放置图像的空间,但我需要确定alertview中可用空间的位置.使用顶部按钮作为参考似乎是找到它的可靠方法.

我尝试了下面的命令,它确实返回了按钮数组(ThreePartButton ??),但是当设置每个按钮的大小时,所有这些按钮的x,y原点都是0.

NSArray *buttonArray = [alertView valueForKey:@"_buttons"];
for (UIControl *aControl in buttonArray)
{
  CGRect rect = aControl.frame;
  NSLog(@"x:%2.2f y:%2.2f w:%2.2f h:%2.2f", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height);
}
Run Code Online (Sandbox Code Playgroud)

任何有关工作解决方案的建议都将不胜感激!

ter*_*ina 5

诀窍是视图的帧在显示之前计算.所以使用UIAlertViewDelegate(例如你创建UIAlertView的类)并实现

- (void)willPresentAlertView:(UIAlertView *)alertView
Run Code Online (Sandbox Code Playgroud)

委托方法.您将访问计算的UIButton的框架.