2016-01-18 20 views
11

Stworzyłem przejście i działa dobrze, oprócz tego, że dostaję czasem czarne rogi w symulatorze. Dodatkowo w iPadzie Pro dostaję całkowicie czarny ekran, jeśli uruchomię symulator w pełnej rozdzielczości. Rozdzielone rozdzielczości działają dobrze. Czy masz pojęcie, jaki może być problem? Inną rzeczą, którą rozpoznałem, jest to, że zawartość za czarnym ekranem jest tam i reaguje na dotyk. Na przykład. po dotknięciu przeładowuję komórkę widoku kolekcji. Wtedy ta komórka jest widoczna, podczas gdy reszta kolekcji jest czarna.Czarny ekran z UIViewControllerAnimatedTransitioning

class ZoomInCircleViewTransition: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate { 

    var transitionContext: UIViewControllerContextTransitioning? 

    func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval { 
     return 0.6 
    } 

    func animateTransition(transitionContext: UIViewControllerContextTransitioning) { 
     self.transitionContext = transitionContext 

     guard let toViewController: UIViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) else { 
      return 
     } 

     guard let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) else {   return 
     } 

     guard let fromViewTransitionFromView = fromViewController as? TransitionFromViewProtocol else { 
      return 
     } 



     let imageViewSnapshot = fromViewTransitionFromView.getViewForTransition() 

     let endFrame = CGRectMake(-CGRectGetWidth(toViewController.view.frame)/2, -CGRectGetHeight(toViewController.view.frame)/2, CGRectGetWidth(toViewController.view.frame)*2, CGRectGetHeight(toViewController.view.frame)*2) 

     if let containerView = transitionContext.containerView(){ 
      containerView.addSubview(fromViewController.view) 
      containerView.addSubview(toViewController.view) 
      containerView.addSubview(imageViewSnapshot) 
     } 


     let maskPath = UIBezierPath(ovalInRect: imageViewSnapshot.frame) 
     let maskLayer = CAShapeLayer() 
     maskLayer.frame = toViewController.view.frame 
     maskLayer.path = maskPath.CGPath 
     toViewController.view.layer.mask = maskLayer 

     let quadraticEndFrame = CGRect(x: endFrame.origin.x - (endFrame.height - endFrame.width)/2, y: endFrame.origin.y, width: endFrame.height, height: endFrame.height) 
     let bigCirclePath = UIBezierPath(ovalInRect: quadraticEndFrame) 

     let pathAnimation = CABasicAnimation(keyPath: "path") 
     pathAnimation.delegate = self 
     pathAnimation.fromValue = maskPath.CGPath 
     pathAnimation.toValue = bigCirclePath 
     pathAnimation.duration = transitionDuration(transitionContext) 
     maskLayer.path = bigCirclePath.CGPath 
     maskLayer.addAnimation(pathAnimation, forKey: "pathAnimation") 


     let hideImageViewAnimation = { 
      imageViewSnapshot.alpha = 0.0 
     } 
     UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: hideImageViewAnimation) { (completed) -> Void in 
     } 

     let scaleImageViewAnimation = { 
      imageViewSnapshot.frame = quadraticEndFrame 
     } 
     UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: scaleImageViewAnimation) { (completed) -> Void in 
      // After the complete animations hav endet 
      imageViewSnapshot.removeFromSuperview() 
     } 
    } 

    override func animationDidStop(anim: CAAnimation, finished flag: Bool) { 
     if let transitionContext = self.transitionContext { 
      transitionContext.completeTransition(!transitionContext.transitionWasCancelled()) 
     } 
    } 

    // MARK: UIViewControllerTransitioningDelegate protocol methods 

    // return the animataor when presenting a viewcontroller 
    func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     return self 
    } 

    // return the animator used when dismissing from a viewcontroller 
    func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
     return self 
    } 
} 

enter image description here

+0

Nazywa się za każdym razem w głównym wątku? – Teddy

+0

Tak, zawsze w głównym wątku – netshark1000

Odpowiedz

5

trzeba usunąć warstwę maski raz Twoje są wykonane z animacji niestandardowej transformacji.

toViewController.view.layer.mask = nil 

Proszę używać tej zaktualizowany kod:

class ZoomInCircleViewTransition: NSObject, UIViewControllerAnimatedTransitioning, UIViewControllerTransitioningDelegate { 

var transitionContext: UIViewControllerContextTransitioning? 

func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval { 
    return 0.6 
} 

func animateTransition(transitionContext: UIViewControllerContextTransitioning) { 
    self.transitionContext = transitionContext 

    guard let toViewController: UIViewController = transitionContext.viewControllerForKey(UITransitionContextToViewControllerKey) else { 
     return 
    } 

    guard let fromViewController = transitionContext.viewControllerForKey(UITransitionContextFromViewControllerKey) else {   return 
    } 

    guard let fromViewTransitionFromView = fromViewController as? TransitionFromViewProtocol else { 
     return 
    } 

    let imageViewSnapshot = fromViewTransitionFromView.getViewForTransition() 

    let endFrame = CGRectMake(-CGRectGetWidth(toViewController.view.frame)/2, -CGRectGetHeight(toViewController.view.frame)/2, CGRectGetWidth(toViewController.view.frame)*2, CGRectGetHeight(toViewController.view.frame)*2) 

    if let containerView = transitionContext.containerView(){ 
     containerView.addSubview(fromViewController.view) 
     containerView.addSubview(toViewController.view) 
     containerView.addSubview(imageViewSnapshot) 
    } 


    let maskPath = UIBezierPath(ovalInRect: imageViewSnapshot.frame) 
    let maskLayer = CAShapeLayer() 
    maskLayer.frame = toViewController.view.frame 
    maskLayer.path = maskPath.CGPath 
    toViewController.view.layer.mask = maskLayer 

    let quadraticEndFrame = CGRect(x: endFrame.origin.x - (endFrame.height - endFrame.width)/2, y: endFrame.origin.y, width: endFrame.height, height: endFrame.height) 
    let bigCirclePath = UIBezierPath(ovalInRect: quadraticEndFrame) 

    let pathAnimation = CABasicAnimation(keyPath: "path") 
    pathAnimation.delegate = self 
    pathAnimation.fromValue = maskPath.CGPath 
    pathAnimation.toValue = bigCirclePath 
    pathAnimation.duration = transitionDuration(transitionContext) 
    maskLayer.path = bigCirclePath.CGPath 
    maskLayer.addAnimation(pathAnimation, forKey: "pathAnimation") 


    let hideImageViewAnimation = { 
     imageViewSnapshot.alpha = 0.0 
    } 

    UIView.animateWithDuration(0.2, delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: hideImageViewAnimation) { (completed) -> Void in 
    } 

    let scaleImageViewAnimation = { 
     imageViewSnapshot.frame = quadraticEndFrame 
    } 
    UIView.animateWithDuration(transitionDuration(transitionContext), delay: 0.0, options: UIViewAnimationOptions.CurveLinear, animations: scaleImageViewAnimation) { (completed) -> Void in 
     // After the complete animations hav endet 
     imageViewSnapshot.removeFromSuperview() 
     toViewController.view.layer.mask = nil 
    } 
} 

override func animationDidStop(anim: CAAnimation, finished flag: Bool) { 
    if let transitionContext = self.transitionContext { 
     transitionContext.completeTransition(!transitionContext.transitionWasCancelled()) 
    } 
} 

// MARK: UIViewControllerTransitioningDelegate protocol methods 

// return the animataor when presenting a viewcontroller 
func animationControllerForPresentedController(presented: UIViewController, presentingController presenting: UIViewController, sourceController source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    return self 
} 

// return the animator used when dismissing from a viewcontroller 
func animationControllerForDismissedController(dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    return self 
} 

}

+0

tak - to rozwiązało czarny ekran! – netshark1000

+0

Czy możesz też rzucić okiem na drugi problem? http://stackoverflow.com/questions/34993774/uiviewcontrolleranimatedtransitioning-black-screen-fragments-after-rotation-cha – netshark1000

+0

Powoduje to inne problemy z znikającym pasku nawigacji: https://stackoverflow.com/questions/35826739/searchbar-behind -navigationbar Być może możesz rzucić okiem? – netshark1000

Powiązane problemy