【发布时间】:2015-12-13 06:54:30
【问题描述】:
我正在尝试创建一个自定义 segue,其中第一个视图控制器缩小一点,第二个在它上面滑动。以下是我的 segue 实现:
override func perform() {
let firstView = self.sourceViewController.view as UIView!
let secondView = self.destinationViewController.view as UIView!
let screenSize = UIScreen.mainScreen().bounds.size
let window = UIApplication.sharedApplication().keyWindow
secondView.frame = CGRectMake(0.0, screenSize.height, screenSize.width, screenSize.height)
window?.insertSubview(secondView, aboveSubview: firstView)
UIView.animateWithDuration(2, delay: 0, options: .CurveEaseIn, animations: {
// BEGIN RELEVANT PORTION
let offset: CGFloat = 20
firstView.frame = CGRectMake(offset, offset, screenSize.width - (offset * 2), screenSize.height - (offset * 2))
firstView.autoresizesSubviews = true
firstView.layoutIfNeeded()
// END RELEVANT PORTION
}, completion: nil)
UIView.animateWithDuration(5, delay: 1, options: .CurveEaseOut, animations: {
secondView.frame = CGRectMake(0.0, 0.0, screenSize.width, screenSize.height)
}, completion: nil)
}
这会产生如下结果:
这已经很棒了,但不是我想要的。我需要子视图(“嗨,我是 Matt。”标签和按钮)与父视图成比例地调整大小,就好像整个视图都在 z 轴上下降一样。
我正在使用自动布局。
非常感谢您!
【问题讨论】:
-
你想让标签和按钮相对于它的 superView 缩小吗?
-
@MuhammadWaqasBhati 是的,这就是我想要做的。 :)
-
您是否在标签和按钮上添加了约束及其超级视图?
-
是的。它们都在超级视图约束中具有中心,标签的水平中心有一个常数
-
我已经在下面添加了答案,告诉我它是否不起作用
标签: ios swift uiview autolayout