Code Monkey home page Code Monkey logo

Comments (2)

CocoaBob avatar CocoaBob commented on August 16, 2024 7

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!) {

    }
}

from rmpzoomtransitionanimator.

mpon avatar mpon commented on August 16, 2024

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.

from rmpzoomtransitionanimator.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.