Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initializer for conditional binding must have optional type, not 'UIView' #5

Open
Andriyas123 opened this issue Sep 30, 2016 · 4 comments

Comments

@Andriyas123
Copy link

Andriyas123 commented Sep 30, 2016

Hello! I am trying to simply run this project but getting an error "Initializer for conditional binding must have optional type, not 'UIView'" in DismissAnimator.swift on the line of "let containerView = transitionContext.containerView":

func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { guard let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from), let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to), let containerView = transitionContext.containerView else { return }

How do I fix that? Thanks!

@TheRyanHickman
Copy link

Its a swift 3 issue, I am too, also hopeful for a solution to the issue.

@chenr2
Copy link
Collaborator

chenr2 commented Oct 11, 2016

Maybe move the let containerView = trainsitionContext.containerView line above the guard statement.

And for the PresentMenuAnimator, move the snapshot into the guard statement.

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        let containerView = transitionContext.containerView
        guard
            let fromVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.from),
            let toVC = transitionContext.viewController(forKey: UITransitionContextViewControllerKey.to),
            let snapshot = fromVC.view.snapshotView(afterScreenUpdates: false)
            else {
                return
        }
        containerView.insertSubview(toVC.view, belowSubview: fromVC.view)

        // replace main view with snapshot
        snapshot.tag = MenuHelper.snapshotNumber
        snapshot.isUserInteractionEnabled = false
        snapshot.layer.shadowOpacity = 0.7
        containerView.insertSubview(snapshot, aboveSubview: toVC.view)
        fromVC.view.isHidden = true

        UIView.animate(
            withDuration: transitionDuration(using: transitionContext),
            animations: {
                snapshot.center.x += UIScreen.main.bounds.width * MenuHelper.menuWidth
            },
            completion: { _ in
                fromVC.view.isHidden = false
                transitionContext.completeTransition(!transitionContext.transitionWasCancelled)
            }
        )
    }

@LgdMagic
Copy link

what is MenuHelper?

@chenr2
Copy link
Collaborator

chenr2 commented May 31, 2017

MenuHelper is just some file that tries to abstract the transition animation code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants