小编Cod*_*eue的帖子

Swift 4表达式类型'@value CGRect'在没有更多上下文的情况下是模糊的

我正在尝试为矩形实现动画以执行模态垂直滑动.但是,当我尝试编译代码时,我得到以下错误"Swift 4表达式类型'@value CGRect'是模糊的,没有更多上下文".我已将问题隔离到传递给CGRect init值的参数,但根据Apple的iOS文档,这些参数应该足以指定我需要设置动画的"帧"视图.

这是我的代码:

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
    guard
        let fromView = transitionContext.viewController(forKey: .from),
        let toView = transitionContext.viewController(forKey: .to)

    else {
            return
    }
    let containerView = transitionContext.containerView
    containerView.insertSubview((toView.view)!, belowSubview: (fromView.view)!)

    let toFrame = transitionContext.finalFrame(for: toView)

    let screenBounds = UIScreen.main.bounds

    let bottomLeftCorner = CGPoint(x: 0, y: screenBounds.height)

    let finalFrameForVC = CGRect(origin: bottomLeftCorner, size: screenBounds.size)

    UIView.animate(withDuration: 2, delay: 1,
                   options: [], (using: transitionContext.finalFrame(for: fromView)),
        animations: {
            fromView.view.frame = finalFrameForVC
    },
        completion: { _ in
            transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
    })
}
Run Code Online (Sandbox Code Playgroud)

cgrect swift

35
推荐指数
6
解决办法
3万
查看次数

标签 统计

cgrect ×1

swift ×1