forked from shadowfacts/Tusker
Use visual effect views for sensitive media hide button so the button is
visible regardless of the image color
This commit is contained in:
parent
42a0a8890c
commit
6ce96764f3
|
@ -105,14 +105,7 @@ class AttachmentView: UIImageView, GIFAnimatable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc func imagePressed() {
|
@objc func imagePressed() {
|
||||||
// switch attachment.kind {
|
delegate?.showAttachmentsGallery(startingAt: index)
|
||||||
// case .image:
|
|
||||||
delegate?.showAttachmentsGallery(startingAt: index)
|
|
||||||
// case .video:
|
|
||||||
// delegate?.showVideo(attachment: attachment)
|
|
||||||
// default:
|
|
||||||
// fatalError()
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,17 +19,17 @@ class AttachmentsContainerView: UIView {
|
||||||
let attachmentViews: NSHashTable<AttachmentView> = .weakObjects()
|
let attachmentViews: NSHashTable<AttachmentView> = .weakObjects()
|
||||||
|
|
||||||
var blurView: UIVisualEffectView?
|
var blurView: UIVisualEffectView?
|
||||||
var hideButton: UIButton?
|
var hideButtonView: UIVisualEffectView?
|
||||||
var contentHidden: Bool! {
|
var contentHidden: Bool! {
|
||||||
didSet {
|
didSet {
|
||||||
guard let blurView = blurView,
|
guard let blurView = blurView,
|
||||||
let hideButton = hideButton else { return }
|
let hideButtonContainerView = hideButtonView else { return }
|
||||||
|
|
||||||
blurView.alpha = contentHidden ? 0 : 1
|
blurView.alpha = contentHidden ? 0 : 1
|
||||||
hideButton.alpha = contentHidden ? 1 : 0
|
hideButtonContainerView.alpha = contentHidden ? 1 : 0
|
||||||
UIView.animate(withDuration: 0.2) {
|
UIView.animate(withDuration: 0.2) {
|
||||||
blurView.alpha = self.contentHidden ? 1 : 0
|
blurView.alpha = self.contentHidden ? 1 : 0
|
||||||
hideButton.alpha = self.contentHidden ? 0 : 1
|
hideButtonContainerView.alpha = self.contentHidden ? 0 : 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,21 +231,43 @@ class AttachmentsContainerView: UIView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func createHideButton() {
|
private func createHideButton() {
|
||||||
let hideButton = UIButton()
|
let blurEffect = UIBlurEffect(style: .regular)
|
||||||
hideButton.translatesAutoresizingMaskIntoConstraints = false
|
let hideButtonBlurView = UIVisualEffectView(effect: blurEffect)
|
||||||
hideButton.alpha = 0
|
hideButtonBlurView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
hideButton.layer.cornerRadius = 2
|
hideButtonBlurView.alpha = 0
|
||||||
hideButton.layer.masksToBounds = true
|
hideButtonBlurView.isUserInteractionEnabled = true
|
||||||
hideButton.setImage(UIImage(systemName: "eye.slash.fill"), for: .normal)
|
hideButtonBlurView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(hideButtonTapped)))
|
||||||
hideButton.addTarget(self, action: #selector(hideButtonTapped), for: .touchUpInside)
|
addSubview(hideButtonBlurView)
|
||||||
|
self.hideButtonView = hideButtonBlurView
|
||||||
|
|
||||||
|
let maskLayer = CALayer()
|
||||||
|
let image = UIImage(systemName: "eye.slash.fill")!
|
||||||
|
maskLayer.contents = image.cgImage!
|
||||||
|
maskLayer.frame = CGRect(origin: .zero, size: image.size)
|
||||||
|
hideButtonBlurView.layer.mask = maskLayer
|
||||||
|
|
||||||
|
let hideButtonVibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: blurEffect, style: .label))
|
||||||
|
hideButtonVibrancyView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
hideButtonBlurView.contentView.addSubview(hideButtonVibrancyView)
|
||||||
|
let fillView = UIView()
|
||||||
|
fillView.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
fillView.backgroundColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 0.5)
|
||||||
|
hideButtonVibrancyView.contentView.addSubview(fillView)
|
||||||
|
|
||||||
addSubview(hideButton)
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
hideButton.topAnchor.constraint(equalTo: topAnchor, constant: 8),
|
hideButtonBlurView.topAnchor.constraint(equalTo: topAnchor, constant: 8),
|
||||||
hideButton.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 8)
|
hideButtonBlurView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 8),
|
||||||
|
hideButtonBlurView.widthAnchor.constraint(equalToConstant: image.size.width),
|
||||||
|
hideButtonBlurView.heightAnchor.constraint(equalToConstant: image.size.height),
|
||||||
|
hideButtonVibrancyView.leadingAnchor.constraint(equalTo: hideButtonBlurView.contentView.leadingAnchor),
|
||||||
|
hideButtonVibrancyView.trailingAnchor.constraint(equalTo: hideButtonBlurView.contentView.trailingAnchor),
|
||||||
|
hideButtonVibrancyView.topAnchor.constraint(equalTo: hideButtonBlurView.contentView.topAnchor),
|
||||||
|
hideButtonVibrancyView.bottomAnchor.constraint(equalTo: hideButtonBlurView.contentView.bottomAnchor),
|
||||||
|
fillView.leadingAnchor.constraint(equalTo: hideButtonBlurView.contentView.leadingAnchor),
|
||||||
|
fillView.trailingAnchor.constraint(equalTo: hideButtonBlurView.contentView.trailingAnchor),
|
||||||
|
fillView.topAnchor.constraint(equalTo: hideButtonBlurView.contentView.topAnchor),
|
||||||
|
fillView.bottomAnchor.constraint(equalTo: hideButtonBlurView.contentView.bottomAnchor),
|
||||||
])
|
])
|
||||||
|
|
||||||
self.hideButton = hideButton
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private func fillView(_ view: UIView, in parentView: UIView? = nil) {
|
private func fillView(_ view: UIView, in parentView: UIView? = nil) {
|
||||||
|
|
Loading…
Reference in New Issue