2017-06-15 9 views
0

私はこの順序でイメージスライダーを表示しています。現在UIViewControllerフレーム

のUIViewController>のUITableView>のUITableViewCell> UICollectionview> UICollectionViewCell> UIImage

ユーザーはUICollectionviewをスライドさせ、images.Problemを表示することができ、私はアニメーションを行う必要があるということです。ユーザーが私のUICollectionviewCellをタップすると、そのセルからアニメーションを作成し、このライブラリのようにフルスクリーンを表示する必要があります。

https://github.com/suzuki-0000/SKPhotoBrowser

問題は、私はMWPhotoBrowserを使用する必要があると私はそのように提示することができないということです。

私はヒーローアニメーションライブラリを使用することも考えています。

https://github.com/lkzhao/Hero

しかし、私のビューhierachyとその例が異なっています。どうすればいいですか?

答えて

1

は、カスタムの移行に使用する必要が

参考:画像の選択に

https://developer.apple.com/library/content/featuredarticles/ViewControllerPGforiPhoneOS/CustomizingtheTransitionAnimations.html

コードワーク

はあなたの助けVC_A

var selectedImage: UIImageView? 
let transition = PopAnimator() 

    override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { 
     super.viewWillTransition(to: size, with: coordinator) 

     coordinator.animate(
      alongsideTransition: {context in 
      self.bgImage.alpha = (size.width>size.height) ? 0.25 : 0.55 
      self.positionListItems() 
      }, 
      completion: nil 
     ) 
     } 
//position all images inside the list 
    func positionListItems() { 
    let listHeight = listView.frame.height 
    let itemHeight: CGFloat = listHeight * 1.33 
    let aspectRatio = UIScreen.main.bounds.height/UIScreen.main.bounds.width 
    let itemWidth: CGFloat = itemHeight/aspectRatio 

    let horizontalPadding: CGFloat = 10.0 

    for i in herbs.indices { 
     let imageView = listView.viewWithTag(i) as! UIImageView 
     imageView.frame = CGRect(
     x: CGFloat(i) * itemWidth + CGFloat(i+1) * horizontalPadding, y: 0.0, 
     width: itemWidth, height: itemHeight) 
    } 

    listView.contentSize = CGSize(
     width: CGFloat(herbs.count) * (itemWidth + horizontalPadding) + horizontalPadding, 
     height: 0) 
    } 

// On image selection 
VC_B.transitioningDelegate = self 
    present(VC_B, animated: true, completion: nil) 



    // add extension 
extension VC_A: UIViewControllerTransitioningDelegate { 

    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    transition.originFrame = selectedImage!.superview!.convert(selectedImage!.frame, to: nil) 

    transition.presenting = true 
    selectedImage!.isHidden = true 

    return transition 
    } 

    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? { 
    transition.presenting = false 
    return transition 
    } 
} 

とアニメーションクラスで

class PopAnimator: NSObject, UIViewControllerAnimatedTransitioning { 

    let duration = 1.0 
    var presenting = true 
    var originFrame = CGRect.zero 

    var dismissCompletion: (()->Void)? 

    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval { 
    return duration 
    } 

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { 
    let containerView = transitionContext.containerView 

    let toView = transitionContext.view(forKey: .to)! 

    let herbView = presenting ? toView : transitionContext.view(forKey: .from)! 

    let initialFrame = presenting ? originFrame : herbView.frame 
    let finalFrame = presenting ? herbView.frame : originFrame 

    let xScaleFactor = presenting ? 

     initialFrame.width/finalFrame.width : 
     finalFrame.width/initialFrame.width 

    let yScaleFactor = presenting ? 

     initialFrame.height/finalFrame.height : 
     finalFrame.height/initialFrame.height 

    let scaleTransform = CGAffineTransform(scaleX: xScaleFactor, y: yScaleFactor) 

    if presenting { 
     herbView.transform = scaleTransform 
     herbView.center = CGPoint(
     x: initialFrame.midX, 
     y: initialFrame.midY) 
     herbView.clipsToBounds = true 
    } 

    containerView.addSubview(toView) 
    containerView.bringSubview(toFront: herbView) 

    UIView.animate(withDuration: duration, delay:0.0, usingSpringWithDamping: 0.4, 
     initialSpringVelocity: 0.0, 
     animations: { 
     herbView.transform = self.presenting ? 
      CGAffineTransform.identity : scaleTransform 
     herbView.center = CGPoint(x: finalFrame.midX, 
            y: finalFrame.midY) 
     }, 
     completion:{_ in 
     if !self.presenting { 
      self.dismissCompletion?() 
     } 
     transitionContext.completeTransition(true) 
     } 
    ) 
    } 

} 
+0

おかげで多くを追加します。私は読んでみると、私のビュー階層に変更する方法がわからない。 可能であれば、私のデモで親切にアドバイスをお願いしますか?私はそれのための小さなプロジェクトを作成しました。ビデオをサポートできるように、MWPhotoBrowserを使用する必要があります。 https://github.com/khantthulinn/photo_tap –

関連する問題