1
0
Fork 0
mirror of https://github.com/metabolist/metatext.git synced 2024-12-29 08:50:27 +00:00
metatext/Transitions/ZoomAnimatableView.swift

44 lines
1.1 KiB
Swift
Raw Normal View History

2020-10-22 05:05:50 +00: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)
}
}