我正在设计一个自定义警报,我正在为其使用在场景停靠栏中设计的 View ,如下所示,以及 Storyboard文件的约束和下拉框链接 https://www.dropbox.com/s/dhk5rrme1j2g89g/Main.storyboard?dl=0 -
现在我通过以下代码添加 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 -
然后我将它旋转到横向 -
2.当模拟器处于横向模式时,我要触摸警报按钮
横向模拟器 -
然后我把它旋转到 potrait****(这是问题来的时候)** -** 我的用户与发送和取消按钮的交互也被禁用。
如何解决上述问题?如何修复警报 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/