Change image zoom animation to take safe area into consideration when determining image origin. Issue #1425
This commit is contained in:
parent
5872893293
commit
9b3793968f
|
@ -520,9 +520,9 @@ private extension ArticleViewController {
|
||||||
|
|
||||||
let base64Image = String(clickMessage.imageURL.suffix(from: range.upperBound))
|
let base64Image = String(clickMessage.imageURL.suffix(from: range.upperBound))
|
||||||
if let imageData = Data(base64Encoded: base64Image), let image = UIImage(data: imageData) {
|
if let imageData = Data(base64Encoded: base64Image), let image = UIImage(data: imageData) {
|
||||||
let rect = CGRect(x: CGFloat(clickMessage.x), y: CGFloat(clickMessage.y), width: CGFloat(clickMessage.width), height: CGFloat(clickMessage.height))
|
let y = CGFloat(clickMessage.y) + webView.safeAreaInsets.top
|
||||||
|
let rect = CGRect(x: CGFloat(clickMessage.x), y: y, width: CGFloat(clickMessage.width), height: CGFloat(clickMessage.height))
|
||||||
transition.originFrame = webView.convert(rect, to: nil)
|
transition.originFrame = webView.convert(rect, to: nil)
|
||||||
transition.maskFrame = webView.convert(webView.frame, to: nil)
|
|
||||||
transition.originImage = image
|
transition.originImage = image
|
||||||
|
|
||||||
coordinator.showFullScreenImage(image: image, transitioningDelegate: self)
|
coordinator.showFullScreenImage(image: image, transitioningDelegate: self)
|
||||||
|
|
|
@ -14,7 +14,6 @@ class ImageTransition: NSObject, UIViewControllerAnimatedTransitioning {
|
||||||
private let duration = 0.4
|
private let duration = 0.4
|
||||||
var presenting = true
|
var presenting = true
|
||||||
var originFrame: CGRect!
|
var originFrame: CGRect!
|
||||||
var maskFrame: CGRect!
|
|
||||||
var originImage: UIImage!
|
var originImage: UIImage!
|
||||||
|
|
||||||
init(controller: ArticleViewController) {
|
init(controller: ArticleViewController) {
|
||||||
|
@ -68,22 +67,11 @@ class ImageTransition: NSObject, UIViewControllerAnimatedTransitioning {
|
||||||
imageView.frame = imageController.zoomedFrame
|
imageView.frame = imageController.zoomedFrame
|
||||||
|
|
||||||
let fromView = transitionContext.view(forKey: .from)!
|
let fromView = transitionContext.view(forKey: .from)!
|
||||||
let windowFrame = fromView.window!.frame
|
|
||||||
fromView.removeFromSuperview()
|
fromView.removeFromSuperview()
|
||||||
|
|
||||||
let toView = transitionContext.view(forKey: .to)!
|
let toView = transitionContext.view(forKey: .to)!
|
||||||
transitionContext.containerView.addSubview(toView)
|
transitionContext.containerView.addSubview(toView)
|
||||||
|
transitionContext.containerView.addSubview(imageView)
|
||||||
let maskingView = UIView()
|
|
||||||
|
|
||||||
let fullMaskFrame = CGRect(x: windowFrame.minX, y: maskFrame.minY, width: windowFrame.width, height: maskFrame.height)
|
|
||||||
let path = UIBezierPath(rect: fullMaskFrame)
|
|
||||||
let maskLayer = CAShapeLayer()
|
|
||||||
maskLayer.path = path.cgPath
|
|
||||||
maskingView.layer.mask = maskLayer
|
|
||||||
|
|
||||||
maskingView.addSubview(imageView)
|
|
||||||
transitionContext.containerView.addSubview(maskingView)
|
|
||||||
|
|
||||||
UIView.animate(
|
UIView.animate(
|
||||||
withDuration: duration,
|
withDuration: duration,
|
||||||
|
|
Loading…
Reference in New Issue