ios - 在应用程序启动时, subview 在设备的不同初始方向上采用不同的帧大小

标签 ios iphone swift uiview uialertview

我正在设计一个自定义警报,我正在为其使用在场景停靠栏中设计的 View ,如下所示,以及 Storyboard文件的约束和下拉框链接 https://www.dropbox.com/s/dhk5rrme1j2g89g/Main.storyboard?dl=0 -

enter image description here enter image description here

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

 @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.当我要触摸警报按钮时模拟器处于肖像模式 -

模拟器中的 potrait -

enter image description here

然后我将它旋转到横向 -

enter image description here

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

横向模拟器 -

enter image description here

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

enter image description here

如何解决上述问题?如何修复警报 View 在屏幕上的正确位置。 编辑 我也尝试了对我的问题投票最多的答案https://stackoverflow.com/a/34610391/5395919但这并没有解决我的问题。

最佳答案

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) 

关于ios - 在应用程序启动时, subview 在设备的不同初始方向上采用不同的帧大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34610125/

相关文章:

iphone - iOS 声音应用程序的 EQ 设置

ios - 将对象添加到实例变量数组

ios - UIView 的阴影效果显示不正确

iphone - iOS:直接访问 MySQL 数据库?

css - 移动优化 : Site wrapper fills screen at 1000px even though iPhone 5s screen is 640px?

ios - 制作属性字符串后的货币符号

iphone - webkit 边框图像未加载移动 safari

iphone - 如果您的网站不支持 Retina,iPhone 4+ 是否会显示两倍大小的图像?

python - 输出 SecKeyCopyExternalRepresentation

ios - swift EXC_BAD_INSTRUCTION