From aa194543d24a0ddf71e31a13f24735490992f041 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 2 Sep 2018 18:22:29 -0400 Subject: [PATCH] Add ability to expand profile avatar & header images --- Tusker/Extensions/UIViewController+Delegates.swift | 7 ++++--- .../View Controllers/LargeImageViewController.swift | 1 + .../LargeImageExpandAnimationController.swift | 3 ++- .../LargeImageShrinkAnimationController.swift | 3 ++- .../Views/ConversationMainStatusTableViewCell.swift | 2 +- Tusker/Views/ProfileHeaderTableViewCell.swift | 12 ++++++++++++ Tusker/Views/ProfileHeaderTableViewCell.xib | 1 + Tusker/Views/StatusTableViewCell.swift | 4 ++-- 8 files changed, 25 insertions(+), 8 deletions(-) diff --git a/Tusker/Extensions/UIViewController+Delegates.swift b/Tusker/Extensions/UIViewController+Delegates.swift index eae9396d..516d1581 100644 --- a/Tusker/Extensions/UIViewController+Delegates.swift +++ b/Tusker/Extensions/UIViewController+Delegates.swift @@ -58,10 +58,10 @@ extension UIViewController: StatusTableViewCellDelegate { present(vc, animated: true) } - func showLargeAttachment(for attachmentView: AttachmentView) { - let vc = LargeImageViewController.create(image: attachmentView.image!, description: attachmentView.attachment.description) + func showLargeImage(_ image: UIImage, description: String?, animatingFrom originView: UIView) { + let vc = LargeImageViewController.create(image: image, description: description) 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 { let scale = scrollView.zoomScale let width = frame.width * scale @@ -71,6 +71,7 @@ extension UIViewController: StatusTableViewCellDelegate { frame = CGRect(x: x, y: y, width: width, height: height) } vc.originFrame = frame + vc.originCornerRadius = originView.layer.cornerRadius vc.transitioningDelegate = self present(vc, animated: true) } diff --git a/Tusker/View Controllers/LargeImageViewController.swift b/Tusker/View Controllers/LargeImageViewController.swift index a50d7f80..fa1e1984 100644 --- a/Tusker/View Controllers/LargeImageViewController.swift +++ b/Tusker/View Controllers/LargeImageViewController.swift @@ -25,6 +25,7 @@ class LargeImageViewController: UIViewController, UIScrollViewDelegate { var delegate: LargeImageViewControllerDelegate? var originFrame: CGRect? + var originCornerRadius: CGFloat? var dismissInteractionController: LargeImageInteractionController? @IBOutlet weak var scrollView: UIScrollView! diff --git a/Tusker/View Controllers/Transitions/LargeImageExpandAnimationController.swift b/Tusker/View Controllers/Transitions/LargeImageExpandAnimationController.swift index eed9b007..8378a188 100644 --- a/Tusker/View Controllers/Transitions/LargeImageExpandAnimationController.swift +++ b/Tusker/View Controllers/Transitions/LargeImageExpandAnimationController.swift @@ -32,7 +32,7 @@ class LargeImageExpandAnimationController: NSObject, UIViewControllerAnimatedTra let imageView = UIImageView(frame: originFrame) imageView.image = toVC.image! imageView.contentMode = .scaleAspectFill - imageView.layer.cornerRadius = 5 + imageView.layer.cornerRadius = toVC.originCornerRadius! imageView.layer.masksToBounds = true let blackView = UIView(frame: finalVCFrame) @@ -48,6 +48,7 @@ class LargeImageExpandAnimationController: NSObject, UIViewControllerAnimatedTra let duration = transitionDuration(using: transitionContext) UIView.animate(withDuration: duration, animations: { imageView.frame = finalFrame + imageView.layer.cornerRadius = 0 blackView.alpha = 1 }, completion: { _ in toVC.view.isHidden = false diff --git a/Tusker/View Controllers/Transitions/LargeImageShrinkAnimationController.swift b/Tusker/View Controllers/Transitions/LargeImageShrinkAnimationController.swift index 0638d65c..e188740c 100644 --- a/Tusker/View Controllers/Transitions/LargeImageShrinkAnimationController.swift +++ b/Tusker/View Controllers/Transitions/LargeImageShrinkAnimationController.swift @@ -39,7 +39,7 @@ class LargeImageShrinkAnimationController: NSObject, UIViewControllerAnimatedTra let imageView = UIImageView(frame: originalFrame) imageView.image = fromVC.image! imageView.contentMode = .scaleAspectFill - imageView.layer.cornerRadius = 5 + imageView.layer.cornerRadius = 0 imageView.layer.masksToBounds = true let blackView = UIView(frame: originalVCFrame) @@ -53,6 +53,7 @@ class LargeImageShrinkAnimationController: NSObject, UIViewControllerAnimatedTra let duration = transitionDuration(using: transitionContext) UIView.animate(withDuration: duration, animations: { imageView.frame = finalFrame + imageView.layer.cornerRadius = fromVC.originCornerRadius! blackView.alpha = 0 }, completion: { _ in blackView.removeFromSuperview() diff --git a/Tusker/Views/ConversationMainStatusTableViewCell.swift b/Tusker/Views/ConversationMainStatusTableViewCell.swift index 0248702a..9498d574 100644 --- a/Tusker/Views/ConversationMainStatusTableViewCell.swift +++ b/Tusker/Views/ConversationMainStatusTableViewCell.swift @@ -167,6 +167,6 @@ extension ConversationMainStatusTableViewCell: HTMLContentLabelDelegate { extension ConversationMainStatusTableViewCell: AttachmentViewDelegate { func showLargeAttachment(for attachmentView: AttachmentView) { - delegate?.showLargeAttachment(for: attachmentView) + delegate?.showLargeImage(attachmentView.image!, description: attachmentView.attachment.description, animatingFrom: attachmentView) } } diff --git a/Tusker/Views/ProfileHeaderTableViewCell.swift b/Tusker/Views/ProfileHeaderTableViewCell.swift index fa41192e..6b0fe1ae 100644 --- a/Tusker/Views/ProfileHeaderTableViewCell.swift +++ b/Tusker/Views/ProfileHeaderTableViewCell.swift @@ -35,6 +35,10 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive { override func awakeFromNib() { avatarContainerView.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() { @@ -88,6 +92,14 @@ class ProfileHeaderTableViewCell: UITableViewCell, PreferencesAdaptive { 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 { diff --git a/Tusker/Views/ProfileHeaderTableViewCell.xib b/Tusker/Views/ProfileHeaderTableViewCell.xib index c151c86e..5147d9c3 100644 --- a/Tusker/Views/ProfileHeaderTableViewCell.xib +++ b/Tusker/Views/ProfileHeaderTableViewCell.xib @@ -44,6 +44,7 @@ + diff --git a/Tusker/Views/StatusTableViewCell.swift b/Tusker/Views/StatusTableViewCell.swift index 453fefa0..9cf058df 100644 --- a/Tusker/Views/StatusTableViewCell.swift +++ b/Tusker/Views/StatusTableViewCell.swift @@ -23,7 +23,7 @@ protocol StatusTableViewCellDelegate { 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 { func showLargeAttachment(for attachmentView: AttachmentView) { - delegate?.showLargeAttachment(for: attachmentView) + delegate?.showLargeImage(attachmentView.image!, description: attachmentView.attachment.description, animatingFrom: attachmentView) } }