2017-12-31 70 views
1

私は、自分のviewControllerをアニメーションで古いviewControllerに却下させたいと思っています。しかし、私がCATransitionを使うと、私のviewControllerと古いviewControllerは黒くなります。フェードしないようにする方法はありますか?セルトランジションでself.dismissのときに黒いフェードを隠す

let transition = CATransition() 
transition.duration = 1.0 
transition.type = kCATransitionPush 
transition.subtype = kCATransitionFromLeft 
view.window!.layer.add(transition, forKey: kCATransition) 
self.dismiss(animated: false, completion: nil) 
+0

'fades black'の意味は?私はそのようなコードを試してみました。 –

答えて

0

移行hereについての詳細を読み、必要な効果を達成するために使用可能なパラメータを変更してみてください。

移行に関する詳細な文書化されていない情報available here

あなたには、いくつかの良い解決策をしたい場合 - あなたはあなたのスクリーンのためのカスタム移行を準備する必要があります - ソリューションのプレゼンテーションを手動で制御することも/あなたのViewControllerに解任このWWDC video

代替の高速(最高ではありません)を確認してください。

ストーリーボードで
import UIKit 

final class AnimatableViewController: UIViewController { 

    private var panStartLocation:CGPoint = CGPoint.zero 
    private var panPrevLocation:CGPoint = CGPoint.zero 

    var onClose:(()->())? 

    // MARK: - LifeCycle 

    override func viewWillAppear(_ animated: Bool) { 
     super.viewWillAppear(animated) 

     openAnimation() 
    } 

    // MARK: - IBAction 

    @objc private func closeButtonAction(_ sender: UIButton) { 
     dismiss(animated: true, completion: { [weak self] in 
      self?.onClose?() 
     }) 
    } 

    // MARK: - Gestures 

    @IBAction private func didDetectPan(_ sender: UIPanGestureRecognizer) { 
     switch sender.state { 
      case .began: 
       panStartLocation = sender.location(in: navigationController?.view) 
       panPrevLocation = panStartLocation 
      case .cancelled, .ended: 
       finishAnimation() 
      case .changed: 
       let newPoint:CGPoint = sender.location(in: navigationController?.view) 
       let dy:CGFloat = newPoint.y - panPrevLocation.y 
       var newPosition:CGPoint = view.center 

       if (newPoint.y - panStartLocation.y > 0) { 
        newPosition.y += dy 
       } else { 
        newPosition.y = self.view.bounds.height/2 
       } 
       view.center = newPosition 
       panPrevLocation = newPoint 
      default: 
       break 
     } 
    } 

    //MARK: Animation 

    private func finishAnimation() { 
     let center:CGPoint = view.center 
     if (center.y > self.view.bounds.height/2 * 1.35) { 
      closeAnimation() 
     } else { 
      openAnimation() 
     } 
    } 

    private func closeAnimation() { 
     let fullAnimTime:CGFloat = 0.5 
     let endPoint:CGPoint = CGPoint(x:view.center.x, y:view.bounds.height/2 * 3) 
     let animTime:CGFloat = ((endPoint.y - view.center.y)/self.view.bounds.height) * fullAnimTime 

     UIView.animate(withDuration: TimeInterval(animTime), animations: { [weak self] in 
      self?.view.center = endPoint 
      }, completion: { [weak self] _ in 
       self?.dismiss(animated: false, completion: { 
        self?.onClose?() 
       }) 
     }) 
    } 

    private func openAnimation() { 
     let fullAnimTime:CGFloat = 0.5 
     let endPoint:CGPoint = CGPoint(x: view.center.x, y:self.view.bounds.height/2) 
     let animTime:CGFloat = ((view.center.y - endPoint.y)/(self.view.bounds.height/2)) * fullAnimTime 
     UIView.animate(withDuration: TimeInterval(animTime)) { [weak self] in 
      self?.view.center = endPoint 
     } 
    } 
} 

extension AnimatableViewController: UIGestureRecognizerDelegate { 
    // MARK: - UIGestureRecognizerDelegate 

    func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { 
     if gestureRecognizer is UIPanGestureRecognizer && otherGestureRecognizer is UIPanGestureRecognizer { 
      return false 
     } 
     return true 
    } 
} 

としてあなたはパラメータをセグエ設定することを忘れないでください:

enter image description here

やパンに使用することができ、ほとんどのビューを、トップにあなたのルートビューまたは任意の追加のパンジェスチャーにpanGestureを追加 - 私の場合 - 私はちょうどrootViewにパンを追加します。

enter image description here

結果:

enter image description here

関連する問題