mastodon-ios/Mastodon/Scene/Transition/MediaPreview/MediaPreviewableViewControl...

31 lines
1.3 KiB
Swift
Raw Normal View History

//
// MediaPreviewableViewController.swift
// Mastodon
//
// Created by MainasuK Cirno on 2021-4-28.
//
import UIKit
protocol MediaPreviewableViewController: UIViewController {
var mediaPreviewTransitionController: MediaPreviewTransitionController { get }
func sourceFrame(transitionItem: MediaPreviewTransitionItem, index: Int) -> CGRect?
}
extension MediaPreviewableViewController {
func sourceFrame(transitionItem: MediaPreviewTransitionItem, index: Int) -> CGRect? {
switch transitionItem.source {
case .attachment(let mediaView):
return mediaView.superview?.convert(mediaView.frame, to: nil)
case .attachments(let mediaGridContainerView):
guard index < mediaGridContainerView.mediaViews.count else { return nil }
let mediaView = mediaGridContainerView.mediaViews[index]
return mediaView.superview?.convert(mediaView.frame, to: nil)
2021-04-28 14:10:17 +02:00
case .profileAvatar(let profileHeaderView):
return profileHeaderView.avatarButton.superview?.convert(profileHeaderView.avatarButton.frame, to: nil)
case .profileBanner(let profileHeaderView):
return profileHeaderView.bannerImageView.superview?.convert(profileHeaderView.bannerImageView.frame, to: nil)
}
}
}