Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed https://github.com/Krisiacik/ImageViewer/issues/190 & https://g… #256

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 47 additions & 32 deletions ImageViewer/Source/ItemBaseController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -434,70 +434,85 @@ open class ItemBaseController<T: UIView>: UIViewController, ItemController, UIGe
// MARK: - Present/Dismiss transitions

public func presentItem(alongsideAnimation: () -> Void, completion: @escaping () -> Void) {

guard isAnimating == false else { return }
isAnimating = true

alongsideAnimation()

if var displacedView = displacedViewsDataSource?.provideDisplacementItem(atIndex: index),
let image = displacedView.image {

let image = displacedView.image {
if presentationStyle == .displacement {

//Prepare the animated imageView
let animatedImageView = displacedView.imageView()

//rotate the imageView to starting angle
if UIApplication.isPortraitOnly == true {
animatedImageView.transform = deviceRotationTransform()
}

//position the image view to starting center
animatedImageView.center = displacedView.convert(displacedView.boundsCenter, to: self.view)

animatedImageView.clipsToBounds = true
self.view.addSubview(animatedImageView)

if displacementKeepOriginalInPlace == false {
displacedView.isHidden = true
}

UIView.animate(withDuration: displacementDuration, delay: 0, usingSpringWithDamping: displacementSpringBounce, initialSpringVelocity: 1, options: .curveEaseIn, animations: { [weak self] in

if UIApplication.isPortraitOnly == true {
animatedImageView.transform = CGAffineTransform.identity
}
/// Animate it into the center (with optionally rotating) - that basically includes changing the size and position

animatedImageView.bounds.size = self?.displacementTargetSize(forSize: image.size) ?? image.size
animatedImageView.center = self?.view.boundsCenter ?? CGPoint.zero

}, completion: { [weak self] _ in

self?.itemView.isHidden = false
displacedView.isHidden = false
animatedImageView.removeFromSuperview()

self?.isAnimating = false
completion()
})

}, completion: { [weak self] _ in

self?.itemView.isHidden = false
displacedView.isHidden = false
animatedImageView.removeFromSuperview()

self?.isAnimating = false
completion()
})
} else {

itemView.alpha = 0
itemView.isHidden = false

UIView.animate(withDuration: itemFadeDuration, animations: { [weak self] in

self?.itemView.alpha = 1

}, completion: { [weak self] _ in

completion()
self?.isAnimating = false
})
}

}

else {

itemView.alpha = 0
itemView.isHidden = false

UIView.animate(withDuration: itemFadeDuration, animations: { [weak self] in

self?.itemView.alpha = 1

self?.itemView.alpha = 1
}, completion: { [weak self] _ in

completion()
self?.isAnimating = false
completion()
self?.isAnimating = false
})
}
}
Expand Down