我想用我的UIView使用相同的解决方案来获得相同的结果。 我有一个带有UIScrollView的UIView。它们嵌入在UINavigationController中。
客户在他们的购物篮中添加商品,我想向他们发送确认消息。现在一个小篮子UIBarButtonItem更新标题以显示项目数。这很好,但不是每个用户/客户都会注意到这一点。
对于这种情况,我真的不喜欢UIAlertView的风格。所以我要添加我自己的UIView并按照我想要的方式设置它。
我正在试图弄清楚如何让UIView显示在窗口的中心。客户是使用iPhone4还是iPhone5。
UIView代码:
UIView *confirmationPopup = [[UIView alloc] initWithFrame:CGRectMake(10, 200, 300, 100)];
[confirmationPopup setBackgroundColor:[UIColor redColor]];
// confirmationPopup.center = [confirmationPopup.superview convertPoint:confirmationPopup.superview.center fromView:confirmationPopup.superview.superview];
[[[self navigationController] view] addSubview:confirmationPopup];
弹出视图自动水平居中,但不是垂直居中。我试着玩你可以看到我注释掉的那条线,但它不会将UIView置于窗口的中心。它似乎将其置于NavBar中心
会感激一些解决方案。
答案 0 :(得分:1)
不要硬编码;使用自动布局。您的custom class for this purpose可能会对您有所帮助,您可以根据需要配置模拟警报视图替代品。它利用了iOS 7自定义演示视图转换。 (当然在iOS 8中会有更多支持这种东西,即UIPresentationController。)