mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Keep a reference to block based notification observer and unregister it manually
This commit is contained in:
parent
1f2565f376
commit
aa40d26274
1 changed files with 8 additions and 1 deletions
|
@ -59,6 +59,7 @@ class PiPView: UIView {
|
|||
private lazy var panGestureRecognizer: UIPanGestureRecognizer = {
|
||||
return UIPanGestureRecognizer(target: self, action: #selector(panned(_:)))
|
||||
}()
|
||||
private var rotationObserver: NSObjectProtocol?
|
||||
|
||||
init() {
|
||||
super.init(frame: .zero)
|
||||
|
@ -116,6 +117,12 @@ class PiPView: UIView {
|
|||
}
|
||||
}
|
||||
|
||||
deinit {
|
||||
if let rotationObserver = rotationObserver {
|
||||
NotificationCenter.default.removeObserver(rotationObserver)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func setup() {
|
||||
|
@ -124,7 +131,7 @@ class PiPView: UIView {
|
|||
layer.cornerRadius = cornerRadius
|
||||
addGestureRecognizer(tapGestureRecognizer)
|
||||
addGestureRecognizer(panGestureRecognizer)
|
||||
_ = NotificationCenter.default.addObserver(forName: UIDevice.orientationDidChangeNotification, object: nil, queue: nil) { [weak self] (_) in
|
||||
rotationObserver = NotificationCenter.default.addObserver(forName: UIDevice.orientationDidChangeNotification, object: nil, queue: nil) { [weak self] (_) in
|
||||
guard let self = self else { return }
|
||||
guard self.superview != nil else { return }
|
||||
self.move(to: self.position, animated: true)
|
||||
|
|
Loading…
Reference in a new issue