在应用程序启动时,子视图在设备的不同初始方向上采用不同的帧大小

Subview taking different frame size in different initial orientation of device in application launch

我正在设计一个自定义警报,我正在为其使用在场景停靠栏中设计的视图,如下所示,以及情节提要文件 https://www.dropbox.com/s/dhk5rrme1j2g89g/Main.storyboard?dl=0-[=19 的约束和下拉框 link =]

现在我通过以下代码添加视图-

 @IBAction func forgotpassword(sender: AnyObject)
    {




                                blurEffect = UIBlurEffect(style: .Dark)
                blurEffectView = UIVisualEffectView(effect: blurEffect)
                blurEffectView.frame = self.contentview.bounds
                blurEffectView.autoresizingMask = [.FlexibleWidth,.FlexibleHeight]


                 AlertVieww.frame = CGRectMake(20, (self.navigationController?.navigationBar.frame.origin.y)! + (navigationController?.navigationBar.frame.height)! + 20, blurEffectView.frame.width-40, self.AlertVieww.frame.height)



                AlertVieww.autoresizingMask = [.FlexibleHeight,.FlexibleWidth]





            blurEffectView.addSubview(self.AlertVieww)



          [self.scrollview.setContentOffset(CGPointZero, animated: false)]
          self.navigationController?.navigationBarHidden = true

        UIView.transitionWithView(self.view.window!, duration: 1.0, options: UIViewAnimationOptions.TransitionFlipFromBottom, animations:
            {


                self.contentview.addSubview(self.blurEffectView)



            }, completion: { finished in


                self.scrollview.scrollEnabled = false



        })

    }

我将发布以下场景以及我的模拟器的屏幕截图 -

1.When 当我要触摸警报按钮时,模拟器处于 potrait 模式 -

模拟器中的 potrait -

然后我将它旋转为横向 -

2.When 当我要触摸警报按钮时,模拟器处于横向模式

横向模拟器 -

然后我把它旋转成potrait****(问题来了)** -** 我的用户与发送和取消按钮的交互也被禁用。

如何解决以上问题?如何修复警报视图在屏幕上的正确位置。 编辑 我也尝试了对我的问题投票最多的答案 但它没有解决我的问题。

setTranslatesAutoresizingMaskIntoConstraints设置为true

来自docs :

By default, the property is set to true for any view you programmatically create. If you add views in Interface Builder, the system automatically sets this property to false.

blurEffectView.autoresizingMask = [.FlexibleWidth,.FlexibleHeight]
blurEffectView.setTranslatesAutoresizingMaskIntoConstraints(true) 

AlertVieww.autoresizingMask = [.FlexibleHeight,.FlexibleWidth]
AlertVieww.setTranslatesAutoresizingMaskIntoConstraints(true) 

为您的警报视图使用自动布局/NSLayoutConstraint。 这可能对你有帮助。

You need to set the following constraints.

1. centerX and centerY constraints for center your alert view.
2. Add the space constraint in between "send" and "cancel" buttons.
3. Add the top constraint for your label and textfield.

阅读以下最佳教程以更好地理解。 http://angelovillegas.com/2014/01/31/ios-nslayoutconstraint/