session-ios/SignalMessaging/ViewControllers/MessageActionsViewController.swift

62 lines
1.7 KiB
Swift
Raw Normal View History

//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@objc
protocol MessageActionsDelegate: class {
func messageActionsDidHide(_ messageActionsViewController: MessageActionsViewController)
}
@objc
class MessageActionsViewController: UIViewController {
@objc
weak var delegate: MessageActionsDelegate?
2018-07-11 00:43:20 +02:00
let focusedView: UIView
@objc
required init(focusedView: UIView) {
self.focusedView = focusedView
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func loadView() {
self.view = UIView()
2018-07-11 00:43:20 +02:00
view.backgroundColor = UIColor.black.withAlphaComponent(0.4)
highlightFocusedView()
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapBackground))
self.view.addGestureRecognizer(tapGesture)
}
2018-07-11 00:43:20 +02:00
private func highlightFocusedView() {
guard let snapshotView = self.focusedView.snapshotView(afterScreenUpdates: false) else {
owsFail("\(self.logTag) in \(#function) snapshotView was unexpectedly nil")
return
}
view.addSubview(snapshotView)
guard let focusedViewSuperview = focusedView.superview else {
owsFail("\(self.logTag) in \(#function) focusedViewSuperview was unexpectedly nil")
return
}
let convertedFrame = view.convert(focusedView.frame, from: focusedViewSuperview)
snapshotView.frame = convertedFrame
}
@objc
func didTapBackground() {
self.delegate?.messageActionsDidHide(self)
}
}