Merge pull request #141 from tootsuite/fix/preview-transition

Fix image transition mask layout issue
This commit is contained in:
CMK 2021-05-27 17:04:55 +08:00 committed by GitHub
commit 629309904a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 12 deletions

View File

@ -163,10 +163,17 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
var needsMaskWithAnimation = true var needsMaskWithAnimation = true
let maskLayerToRect: CGRect? = { let maskLayerToRect: CGRect? = {
guard case .mosaic = transitionItem.source else { return nil } guard case .mosaic = transitionItem.source else { return nil }
guard let navigationBar = toVC.navigationController?.navigationBar else { return nil } guard let navigationBar = toVC.navigationController?.navigationBar, let navigationBarSuperView = navigationBar.superview else { return nil }
let navigationBarFrameInWindow = toVC.view.convert(navigationBar.frame, to: nil) let navigationBarFrameInWindow = navigationBarSuperView.convert(navigationBar.frame, to: nil)
// crop rect top edge
var rect = transitionMaskView.frame var rect = transitionMaskView.frame
let _toViewFrameInWindow = toVC.view.superview.flatMap { $0.convert(toVC.view.frame, to: nil) }
if let toViewFrameInWindow = _toViewFrameInWindow, toViewFrameInWindow.minY > navigationBarFrameInWindow.maxY {
rect.origin.y = toViewFrameInWindow.minY
} else {
rect.origin.y = navigationBarFrameInWindow.maxY + UIView.separatorLineHeight(of: toVC.view) // extra hairline rect.origin.y = navigationBarFrameInWindow.maxY + UIView.separatorLineHeight(of: toVC.view) // extra hairline
}
if rect.minY < snapshot.frame.minY { if rect.minY < snapshot.frame.minY {
needsMaskWithAnimation = false needsMaskWithAnimation = false
@ -177,8 +184,8 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
let maskLayerToPath = maskLayerToRect.flatMap { UIBezierPath(rect: $0) }?.cgPath let maskLayerToPath = maskLayerToRect.flatMap { UIBezierPath(rect: $0) }?.cgPath
let maskLayerToFinalRect: CGRect? = { let maskLayerToFinalRect: CGRect? = {
guard case .mosaic = transitionItem.source else { return nil } guard case .mosaic = transitionItem.source else { return nil }
guard let tabBarController = toVC.tabBarController else { return nil } guard let tabBarController = toVC.tabBarController, let tabBarSuperView = tabBarController.tabBar.superview else { return nil }
let tabBarFrameInWindow = toVC.view.convert(tabBarController.tabBar.frame, to: nil) let tabBarFrameInWindow = tabBarSuperView.convert(tabBarController.tabBar.frame, to: nil)
var rect = maskLayerToRect ?? transitionMaskView.frame var rect = maskLayerToRect ?? transitionMaskView.frame
let offset = rect.maxY - tabBarFrameInWindow.minY let offset = rect.maxY - tabBarFrameInWindow.minY
guard offset > 0 else { return rect } guard offset > 0 else { return rect }
@ -411,10 +418,17 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
var needsMaskWithAnimation = true var needsMaskWithAnimation = true
let maskLayerToRect: CGRect? = { let maskLayerToRect: CGRect? = {
guard case .mosaic = transitionItem.source else { return nil } guard case .mosaic = transitionItem.source else { return nil }
guard let navigationBar = toVC.navigationController?.navigationBar else { return nil } guard let navigationBar = toVC.navigationController?.navigationBar, let navigationBarSuperView = navigationBar.superview else { return nil }
let navigationBarFrameInWindow = toVC.view.convert(navigationBar.frame, to: nil) let navigationBarFrameInWindow = navigationBarSuperView.convert(navigationBar.frame, to: nil)
// crop rect top edge
var rect = transitionMaskView.frame var rect = transitionMaskView.frame
rect.origin.y = navigationBarFrameInWindow.maxY let _toViewFrameInWindow = toVC.view.superview.flatMap { $0.convert(toVC.view.frame, to: nil) }
if let toViewFrameInWindow = _toViewFrameInWindow, toViewFrameInWindow.minY > navigationBarFrameInWindow.maxY {
rect.origin.y = toViewFrameInWindow.minY
} else {
rect.origin.y = navigationBarFrameInWindow.maxY + UIView.separatorLineHeight(of: toVC.view) // extra hairline
}
if rect.minY < snapshot.frame.minY { if rect.minY < snapshot.frame.minY {
needsMaskWithAnimation = false needsMaskWithAnimation = false
@ -430,8 +444,8 @@ extension MediaHostToMediaPreviewViewControllerAnimatedTransitioning {
let maskLayerToFinalRect: CGRect? = { let maskLayerToFinalRect: CGRect? = {
guard case .mosaic = transitionItem.source else { return nil } guard case .mosaic = transitionItem.source else { return nil }
guard let tabBarController = toVC.tabBarController else { return nil } guard let tabBarController = toVC.tabBarController, let tabBarSuperView = tabBarController.tabBar.superview else { return nil }
let tabBarFrameInWindow = toVC.view.convert(tabBarController.tabBar.frame, to: nil) let tabBarFrameInWindow = tabBarSuperView.convert(tabBarController.tabBar.frame, to: nil)
var rect = maskLayerToRect ?? transitionMaskView.frame var rect = maskLayerToRect ?? transitionMaskView.frame
let offset = rect.maxY - tabBarFrameInWindow.minY let offset = rect.maxY - tabBarFrameInWindow.minY
guard offset > 0 else { return rect } guard offset > 0 else { return rect }