0

设想:

我创建了一个“attributeView”(UITableView),它是一个子视图(即容器 UIViewController 的视图的成员 UIViewController 的视图),将沿父视图的右上角显示。

它由上下文 (UITableView) 菜单的用户选择(未显示)激活。

在此处输入图像描述

目标:将此 UIView 动画化为从屏幕右边缘 滑动的视图。
基本上,就像一个滑动抽屉。

以下 snapkit 代码定位属性视图。我正在考虑从零宽度视图开始,然后动画到全宽:

public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
...
let attributeView = viewControllerToPresent.view
let containerView = presentingViewController?.view

presentingViewController?.addChildViewController(viewControllerToPresent)
containerView?.addSubview(attributeView!)

attributeView?.snp.makeConstraints { (make) in
    make.width.equalTo(0.0)
    make.top.equalTo(containerView!).offset(00.0)
    make.right.equalTo(containerView!).offset(0.0)
    make.bottom.equalTo(containerView!).offset(0.0)
}

UIView.animate(withDuration: 0.3,
               animations: {
                attributeView?.snp.updateConstraints { (update) in
                    update.width.equalTo(320.0)
                }
                self.layoutIfNeeded()
})

viewControllerToPresent.didMove(toParentViewController: presentingViewController)

但这不起作用。我尝试了各种使用 snapkit 为宽度设置动画的方法。但我无法让它从右边缘滑入视野。

这样做的正确方法是什么?
还是我必须在没有 snapkit 的情况下手动定位视图并从那里开始?

4

1 回答 1

0

您需要设置左侧约束,使其从屏幕开始。

attributeView?.snp.makeConstraints { (make) in
    make.width.equalTo(0.0)
    make.top.equalTo(containerView!).offset(00.0)
    make.right.equalTo(containerView!).offset(0.0)
    make.left.equalTo(containerView!.snp.right)
    make.bottom.equalTo(containerView!).offset(0.0)
}

UIView.animate(withDuration: 0.3,
           animations: {
            attributeView?.snp.updateConstraints { (update) in
                update.left.equalTo(containerView!.snp.right).offset(-320.0)
            }
            self.layoutIfNeeded()
})
于 2017-04-25T17:13:21.483 回答