请参阅:Dual Container View Animation iOS了解我的观点的描述以及我正在尝试做的事情的详细信息。
基本上,它是两个动画容器 View 。在上述线程中,我正在对帧进行动画处理,但我发现它存在问题。
我现在已经开始为约束和框架设置动画,但是
1) 我不确定自己的做法是否正确。 2)当我旋转设备然后将其旋转回来时,动画 View 会向后移动。
激活自动旋转后,如何防止动画 View 消失?提前致谢。
我的隐藏/显示代码:
func hideBanner() {
guard isBannerShowing == true else { return }
self.isBannerShowing = false
let adjustment = self.cancelApplyView.frame.size.height
let tableViewFrame = tableContainerView.frame
let newTableViewFrame = CGRect(x: tableViewFrame.origin.x, y: tableViewFrame.origin.y, width: tableViewFrame.size.width, height: tableViewFrame.height + adjustment)
let cancelApplyFrame = cancelApplyView.frame
let newCancelApplyFrame = CGRect(x: cancelApplyFrame.origin.x, y: cancelApplyFrame.origin.y + adjustment, width: cancelApplyFrame.size.width, height: cancelApplyFrame.height)
self.view.updateConstraints()
UIView.animate(withDuration: 0.5, animations: {
self.tableContainerBottomConstraint.constant = 0
self.view.layoutIfNeeded()
self.tableContainerView.frame = newTableViewFrame
self.cancelApplyView.frame = newCancelApplyFrame
})
}
func showBanner() {
guard isBannerShowing == false else { return }
self.isBannerShowing = true
let adjustment = self.cancelApplyView.frame.size.height
let newConstraintVal = cancelApplyView.frame.size.height
let tableViewFrame = tableContainerView.frame
let newTableViewFrame = CGRect(x: tableViewFrame.origin.x, y: tableViewFrame.origin.y, width: tableViewFrame.size.width, height: tableViewFrame.height - adjustment)
let cancelApplyFrame = cancelApplyView.frame
let newCancelApplyFrame = CGRect(x: cancelApplyFrame.origin.x, y: cancelApplyFrame.origin.y - adjustment, width: cancelApplyFrame.size.width, height: cancelApplyFrame.height)
self.view.bringSubview(toFront: self.cancelApplyView)
self.view.updateConstraints()
UIView.animate(withDuration: 0.5, animations: {
self.tableContainerBottomConstraint.constant = newConstraintVal
self.view.layoutIfNeeded()
self.tableContainerView.frame = newTableViewFrame
self.cancelApplyView.frame = newCancelApplyFrame
})
}
最佳答案
实际上你不必同时进行自动/框架布局更改
将横幅顶部约束 Hook 到表格,并使横幅的底部 = view.bottom + BannerHeight
隐藏
self.bannerTopConstraint.constant = -1* bannerHeight
self.cancelApplyViewTopConstraint.constant = 0
UIView.animate(withDuration: 0.5, animations: {
self.view.layoutIfNeeded()
})
显示
self.bannerTopConstraint.constant = 0
self.cancelApplyViewTopConstraint.constant = -1 * adjustment
UIView.animate(withDuration: 0.5, animations: {
self.view.layoutIfNeeded()
})
关于iOS 动画 View 在自动旋转后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48329586/