Add ability to expand profile avatar & header images
This commit is contained in:
parent
e587bb3221
commit
9732376843
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
<subviews>
|
||||
<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"/>
|
||||
<gestureRecognizers/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="width" constant="116" id="k9v-I0-Aoz"/>
|
||||
<constraint firstAttribute="height" constant="116" id="sz5-86-5Iq"/>
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue