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

cant conform to RMPZoomTransitionAnimating protocol #9

Open
M1ndaugasJ opened this issue Oct 24, 2015 · 2 comments
Open

cant conform to RMPZoomTransitionAnimating protocol #9

M1ndaugasJ opened this issue Oct 24, 2015 · 2 comments

Comments

@M1ndaugasJ
Copy link

Hi

I'm trying to implement this animation in a Swift project.
The problem I'm facing is that whenever my destinationController or sourceController is checked in RMPZoomTransitionAnimator.m for conformity to the RMPZoomTransitionAnimating protocol the check always fails, even though I implement the protocol in the controllers.

What is there that I don't know?

@mpon
Copy link
Member

mpon commented Nov 1, 2015

Hi, @iamsoheavy

Did you implement following methods?

- (UIImageView *)transitionSourceImageView;
- (UIColor *)transitionSourceBackgroundColor;
- (CGRect)transitionDestinationImageViewFrame;

If you show the example code to fail check protocol, I will support in detail.

@CocoaBob
Copy link
Contributor

Hello, here's an example from my project, it works well in Swift 2 (except "supporting UIViewControllerInteractiveTransitioning" and "incorrect layout after dismissing view controller after rotating the screen").

You need to use as? protocol<RMPZoomTransitionAnimating, RMPZoomTransitionDelegate> to replace the ObjC codes id <RMPZoomTransitionAnimating, RMPZoomTransitionDelegate>.

You need to inherit both RMPZoomTransitionAnimating and RMPZoomTransitionDelegate to make sure animator.sourceTransition and animator.destinationTransition are not nil.

// MARK: - UINavigationControllerDelegate
extension NewsViewController: UINavigationControllerDelegate {

    func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? {
        if fromVC is RMPZoomTransitionAnimating && toVC is RMPZoomTransitionAnimating {
            let animator = RMPZoomTransitionAnimator()
            animator.goingForward = (operation == .Push)
            animator.sourceTransition = fromVC as? protocol<RMPZoomTransitionAnimating, RMPZoomTransitionDelegate>
            animator.destinationTransition = toVC as? protocol<RMPZoomTransitionAnimating, RMPZoomTransitionDelegate>
            return animator
        } else {
            return nil
        }
    }
}

// MARK: - RMPZoomTransitionAnimating/RMPZoomTransitionDelegate
extension NewsViewController: RMPZoomTransitionAnimating, RMPZoomTransitionDelegate {

    func imageViewFrame() -> CGRect {
        if let collectionView = self.collectionView(),
            let indexPath = self.selectedIndexPath,
            let cell = collectionView.cellForItemAtIndexPath(indexPath) as? NewsCollectionViewCell,
            let imageView = cell.fgImageView {
                let frame = imageView.convertRect(imageView.frame, toView: self.view.window)
                return frame
        }
        return CGRectZero
    }

    func transitionSourceImageView() -> UIImageView! {
        let imageView = UIImageView()
        imageView.clipsToBounds = true
        imageView.userInteractionEnabled = false
        imageView.contentMode = .ScaleAspectFill
        imageView.frame = imageViewFrame()
        imageView.image = self.selectedNewsViewCell?.fgImageView!.image
        return imageView
    }

    func transitionSourceBackgroundColor() -> UIColor! {
        return UIColor.whiteColor()
    }

    func transitionDestinationImageViewFrame() -> CGRect {
        return imageViewFrame()
    }

    func zoomTransitionAnimator(animator: RMPZoomTransitionAnimator!, didCompleteTransition didComplete: Bool, animatingSourceImageView imageView: UIImageView!) {

    }
}

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

3 participants