iOS 动画 View 在自动旋转后消失

标签 ios animation

请参阅: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/

相关文章:

ios - Xcode8/SDK iOS 10.2 设备、配置文件和代码签名问题

java - Android - 移动布局或动画项目到购物车

javascript - Snap.svg 动画运行多次以不同的值结束

javascript - body 动画不流畅

javascript - 对于动态添加的元素,动画无法正常工作

iphone - 使用 AVCaptureSession 录制视频

ios - 从网站加载 iOS 应用程序资源

ios - 如何在缓存中存储图像数据

iphone - 应调用哪个 TextField 委托(delegate)方法?

java - Java2d 中的动画图像