【问题标题】:UIView animation is clippingUIView 动画正在剪辑
【发布时间】:2021-12-23 02:44:46
【问题描述】:

我正在尝试制作动画,但我不知道我做错了什么。我希望动画能够使菜单在向下滚动时放大,但由于在完成放大后会受到限制,它会继续剪辑。

我尽我所知尝试改变顺序,或者只是为了保持顶部固定,但直到现在我都没有成功。

(请参阅 Imgur 链接以获取我的意思的 gif 文件,即位置的突然跳跃)

menuHeightConstraint 是 UIView 高度的约束

IBAction函数代码

@IBAction func openMenu() {
        menuIsOpen.toggle()
        menuHeightConstraint.constant = menuIsOpen ? 180 : 55
        logoHorizontalConstraint.constant = menuIsOpen ? 0 : -122
        logoVerticalConstraint.constant = menuIsOpen ? 15 : 7
        logoHeight.constant = menuIsOpen ? 75 : 40
        logoWidth.constant = menuIsOpen ? 75 : 40
        loginVertConstraint.constant = menuIsOpen ? 100 : 15 // label constraint
        
        let indicator = menuIsOpen ? UIImage(systemName: "arrow.up.circle.fill") : UIImage(systemName: "arrow.down.circle.fill")
        
        dropDownButtonImage.setImage(indicator, for: .normal)
        
        UIView.animate(
            withDuration: 0.5,
            delay: 0,
            options: .curveEaseIn,
            animations: {
                self.menuView.layoutIfNeeded()
                
            },
            completion: nil)
    }

Link to GIF -----,
constraint in storyboard

【问题讨论】:

    标签: ios swift uiviewanimation


    【解决方案1】:

    在您的 animations 块中,更改:

    self.menuView.layoutIfNeeded()
    

    到:

    self.view.layoutIfNeeded()
    

    【讨论】:

    • 这确实有效!谢谢!
    猜你喜欢
    • 2015-06-15
    • 2018-03-16
    • 1970-01-01
    • 2015-12-25
    • 2019-08-26
    • 1970-01-01
    • 2012-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多