2015-10-23 3 views
0

Я пытаюсь преобразовать код в быстройObjective C для Swift преобразования (протокол)

- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController 
            animationControllerForOperation:(UINavigationControllerOperation)operation 
               fromViewController:(UIViewController *)fromVC 
                toViewController:(UIViewController *)toVC 
{ 
    // minimum implementation for example 
    RMPZoomTransitionAnimator *animator = [[RMPZoomTransitionAnimator alloc] init]; 
    animator.goingForward = (operation == UINavigationControllerOperationPush); 
    animator.sourceTransition = (id<RMPZoomTransitionAnimating>)fromVC; 
    animator.destinationTransition = (id<RMPZoomTransitionAnimating>)toVC; 
    return animator; 
} 

мне удалось преобразовать до сих пор, но мне интересно, как я должен преобразовать это (id<RMPZoomTransitionAnimating>)fromVC

func navigationController(navigationController: UINavigationController, animationControllerForOperation operation: UINavigationControllerOperation, fromViewController fromVC: UIViewController, toViewController toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    let animator: RMPZoomTransitionAnimator = RMPZoomTransitionAnimator(); 

    animator.goingForward = (operation == UINavigationControllerOperation.Push); 
    animator.sourceTransition = fromVC as! RMPZoomTransitionAnimating;//DOESN'T COMPILE 
    animator.destinationTransition = toVC as! RMPZoomTransitionAnimating;//DOESN'T COMPILE 
    return animator; 
} 

Я понятия не имею, что называется. Любая идея, что это? Я пытался бросить его, но он не работает

Screenshot

+0

Что такое ошибка? – titaniumdecoy

ответ

0

Вы можете бросить, как показано ниже:

animator.sourceTransition = fromVC as? protocol<RMPZoomTransitionAnimating, RMPZoomTransitionDelegate> 

Отливка только успешным, когда fromVC соответствуют оба протокола RMPZoomTransitionAnimating и RMPZoomTransitionDelegate

P/S: Вы должны забыть semi-colon при кодировании Swift

1

RMPZoomTransitionAnimator расширение swift3.0

extension ViewController: UINavigationControllerDelegate { 

func navigationController(_ navigationController: UINavigationController, animationControllerFor operation: UINavigationControllerOperation, from fromVC: UIViewController, to toVC: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    if fromVC is RMPZoomTransitionAnimating && toVC is RMPZoomTransitionAnimating { 
     let animator = RMPZoomTransitionAnimator() 
     animator.goingForward = (operation == .push) 
     animator.sourceTransition = fromVC as? RMPZoomTransitionAnimating & RMPZoomTransitionDelegate 
     animator.destinationTransition = toVC as? RMPZoomTransitionAnimating & RMPZoomTransitionDelegate 
     return animator 
    } else { 
     return nil 
    } 
    } 
} 

extension ViewController: 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 CGRect.zero 
} 

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

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

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

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

} 
}