metatext-app-ios-iphone-ipad/Transitions/ZoomAnimatableView.swift

44 lines
1.1 KiB
Swift
Raw Normal View History

2020-10-22 07:05:50 +02:00
// Copyright © 2020 Metabolist. All rights reserved.
import AVFoundation
import UIKit
protocol ZoomAnimatableView {
func transitionView() -> UIView
func frame(inView view: UIView) -> CGRect
}
extension UIImageView: ZoomAnimatableView {
func transitionView() -> UIView {
let transitionView = UIImageView(image: image)
transitionView.contentMode = .scaleAspectFill
transitionView.clipsToBounds = true
return transitionView
}
func frame(inView view: UIView) -> CGRect {
guard let image = image else { return .zero }
return AVMakeRect(aspectRatio: image.size, insideRect: view.frame)
}
}
extension PlayerView: ZoomAnimatableView {
func transitionView() -> UIView {
let transitionView = PlayerView()
transitionView.videoGravity = .resizeAspectFill
transitionView.player = player
return transitionView
}
func frame(inView view: UIView) -> CGRect {
guard let item = player?.currentItem else { return .zero }
return AVMakeRect(aspectRatio: item.presentationSize, insideRect: view.frame)
}
}