Add ability to expand profile avatar & header images

This commit is contained in:
Shadowfacts 2018-09-02 18:22:29 -04:00
parent 43ea836a1f
commit f6e9d40e25
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
8 changed files with 25 additions and 8 deletions

View File

@ -58,10 +58,10 @@ extension UIViewController: StatusTableViewCellDelegate {
present(vc, animated: true) present(vc, animated: true)
} }
func showLargeAttachment(for attachmentView: AttachmentView) { func showLargeImage(_ image: UIImage, description: String?, animatingFrom originView: UIView) {
let vc = LargeImageViewController.create(image: attachmentView.image!, description: attachmentView.attachment.description) let vc = LargeImageViewController.create(image: image, description: description)
vc.delegate = self vc.delegate = self
var frame = attachmentView.convert(attachmentView.bounds, to: view) var frame = originView.convert(originView.bounds, to: view)
if let scrollView = view as? UIScrollView { if let scrollView = view as? UIScrollView {
let scale = scrollView.zoomScale let scale = scrollView.zoomScale
let width = frame.width * scale let width = frame.width * scale
@ -71,6 +71,7 @@ extension UIViewController: StatusTableViewCellDelegate {
frame = CGRect(x: x, y: y, width: width, height: height) frame = CGRect(x: x, y: y, width: width, height: height)
} }
vc.originFrame = frame vc.originFrame = frame
vc.originCornerRadius = originView.layer.cornerRadius
vc.transitioningDelegate = self vc.transitioningDelegate = self
present(vc, animated: true) present(vc, animated: true)
} }

View File

@ -25,6 +25,7 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate {
var delegate: LargeImageViewControllerDelegate? var delegate: LargeImageViewControllerDelegate?
var originFrame: CGRect? var originFrame: CGRect?
var originCornerRadius: CGFloat?
var dismissInteractionController: LargeImageInteractionController? var dismissInteractionController: LargeImageInteractionController?
@IBOutlet weak var scrollView: UIScrollView! @IBOutlet weak var scrollView: UIScrollView!

View File

@ -32,7 +32,7 @@ class LargeImageExpandAnimationController: NSObject, UIViewControllerAnimatedTra
let imageView = UIImageView(frame: originFrame) let imageView = UIImageView(frame: originFrame)
imageView.image = toVC.image! imageView.image = toVC.image!
imageView.contentMode = .scaleAspectFill imageView.contentMode = .scaleAspectFill
imageView.layer.cornerRadius = 5 imageView.layer.cornerRadius = toVC.originCornerRadius!
imageView.layer.masksToBounds = true imageView.layer.masksToBounds = true
let blackView = UIView(frame: finalVCFrame) let blackView = UIView(frame: finalVCFrame)
@ -48,6 +48,7 @@ class LargeImageExpandAnimationController: NSObject, UIViewControllerAnimatedTra
let duration = transitionDuration(using: transitionContext) let duration = transitionDuration(using: transitionContext)
UIView.animate(withDuration: duration, animations: { UIView.animate(withDuration: duration, animations: {
imageView.frame = finalFrame imageView.frame = finalFrame
imageView.layer.cornerRadius = 0
blackView.alpha = 1 blackView.alpha = 1
}, completion: { _ in }, completion: { _ in
toVC.view.isHidden = false toVC.view.isHidden = false

View File

@ -39,7 +39,7 @@ class LargeImageShrinkAnimationController: NSObject, UIViewControllerAnimatedTra
let imageView = UIImageView(frame: originalFrame) let imageView = UIImageView(frame: originalFrame)
imageView.image = fromVC.image! imageView.image = fromVC.image!
imageView.contentMode = .scaleAspectFill imageView.contentMode = .scaleAspectFill
imageView.layer.cornerRadius = 5 imageView.layer.cornerRadius = 0
imageView.layer.masksToBounds = true imageView.layer.masksToBounds = true
let blackView = UIView(frame: originalVCFrame) let blackView = UIView(frame: originalVCFrame)
@ -53,6 +53,7 @@ class LargeImageShrinkAnimationController: NSObject, UIViewControllerAnimatedTra
let duration = transitionDuration(using: transitionContext) let duration = transitionDuration(using: transitionContext)
UIView.animate(withDuration: duration, animations: { UIView.animate(withDuration: duration, animations: {
imageView.frame = finalFrame imageView.frame = finalFrame
imageView.layer.cornerRadius = fromVC.originCornerRadius!
blackView.alpha = 0 blackView.alpha = 0
}, completion: { _ in }, completion: { _ in
blackView.removeFromSuperview() blackView.removeFromSuperview()

View File

@ -167,6 +167,6 @@ extension ConversationMainStatusTableViewCell: HTMLContentLabelDelegate {
extension ConversationMainStatusTableViewCell: AttachmentViewDelegate { extension ConversationMainStatusTableViewCell: AttachmentViewDelegate {
func showLargeAttachment(for attachmentView: AttachmentView) { func showLargeAttachment(for attachmentView: AttachmentView) {
delegate?.showLargeAttachment(for: attachmentView) delegate?.showLargeImage(attachmentView.image!, description: attachmentView.attachment.description, animatingFrom: attachmentView)
} }
} }

View File

@ -35,6 +35,10 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive {
override func awakeFromNib() { override func awakeFromNib() {
avatarContainerView.layer.masksToBounds = true avatarContainerView.layer.masksToBounds = true
avatarImageView.layer.masksToBounds = true avatarImageView.layer.masksToBounds = true
avatarImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(avatarPressed)))
avatarImageView.isUserInteractionEnabled = true
headerImageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(headerPressed)))
headerImageView.isUserInteractionEnabled = true
} }
func updateUIForPreferences() { func updateUIForPreferences() {
@ -88,6 +92,14 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive {
delegate?.showMoreOptions() delegate?.showMoreOptions()
} }
@objc func avatarPressed() {
delegate?.showLargeImage(avatarImageView.image!, description: nil, animatingFrom: avatarImageView)
}
@objc func headerPressed() {
delegate?.showLargeImage(headerImageView.image!, description: nil, animatingFrom: headerImageView)
}
} }
extension ProfileHeaderTableViewCell: HTMLContentLabelDelegate { extension ProfileHeaderTableViewCell: HTMLContentLabelDelegate {

View File

@ -44,6 +44,7 @@
<subviews> <subviews>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="tH8-sR-DHC"> <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="tH8-sR-DHC">
<rect key="frame" x="2" y="2" width="116" height="116"/> <rect key="frame" x="2" y="2" width="116" height="116"/>
<gestureRecognizers/>
<constraints> <constraints>
<constraint firstAttribute="width" constant="116" id="k9v-I0-Aoz"/> <constraint firstAttribute="width" constant="116" id="k9v-I0-Aoz"/>
<constraint firstAttribute="height" constant="116" id="sz5-86-5Iq"/> <constraint firstAttribute="height" constant="116" id="sz5-86-5Iq"/>

View File

@ -23,7 +23,7 @@ protocol StatusTableViewCellDelegate {
func reply(to status: Status) func reply(to status: Status)
func showLargeAttachment(for attachmentView: AttachmentView) func showLargeImage(_ image: UIImage, description: String?, animatingFrom originView: UIView)
} }
@ -210,6 +210,6 @@ extension StatusTableViewCell: HTMLContentLabelDelegate {
extension StatusTableViewCell: AttachmentViewDelegate { extension StatusTableViewCell: AttachmentViewDelegate {
func showLargeAttachment(for attachmentView: AttachmentView) { func showLargeAttachment(for attachmentView: AttachmentView) {
delegate?.showLargeAttachment(for: attachmentView) delegate?.showLargeImage(attachmentView.image!, description: attachmentView.attachment.description, animatingFrom: attachmentView)
} }
} }