【问题标题】:Slide WebView up on top of hidden view - Swift将 WebView 向上滑动到隐藏视图的顶部 - Swift
【发布时间】:2017-02-16 20:58:54
【问题描述】:

到目前为止,我已经做到了,当用户打开侧边菜单时,视图将隐藏,但是,一旦我尝试使用下面的代码进行动画处理,动画/转换就没有发生。

代码(WebViewTst 是 WebView)(animView 是被隐藏的视图)(高度约束在我删除它之前对视图的约束):

    if(revealController.frontViewPosition == FrontViewPosition.right){


        animView.isHidden = true


        UIView.animate(withDuration: 0.5, animations: {
            self.view.layoutIfNeeded()
            self.WebViewTst.layer.zPosition = 1
            self.heightConstraint.constant = 595

        })

    }

任何帮助将不胜感激。

【问题讨论】:

    标签: swift uiwebview uiviewanimation


    【解决方案1】:

    尝试在布局约束之后调用 self.view.layoutIfNeeded()。

    另一种制作动画的方法是使用过渡。你可以制作这个动画块:

    UIView.animate(withDuration: 0.5, animations: {
        self.WebViewTst.transform = CGAffineTransformMakeTranslation(0, 595;
    }
    

    (我不确定你是否需要 dy -595 或 595)

    当你想重置 WebViewTst 位置时,只需调用:

    self.WebViewTst.transform = CGAffineTransformIdentity
    

    【讨论】:

    • 这对我有用。只需将595更改为-65,它就可以正常工作。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-08-20
    • 1970-01-01
    • 1970-01-01
    • 2013-11-14
    • 1970-01-01
    • 2011-07-17
    • 2023-04-11
    • 1970-01-01
    相关资源
    最近更新 更多