Skip to content

Commit 7a9f562

Browse files
committed
Fixed bug with rotation device.
1 parent 30def4c commit 7a9f562

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

SPIndicator.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Pod::Spec.new do |s|
22

33
s.name = 'SPIndicator'
4-
s.version = '1.4.2'
4+
s.version = '1.5.0'
55
s.summary = 'Floating indicator, mimicrate to indicator which appear when silent mode turn on / off. Support large texts.'
66
s.homepage = 'https://github.com/ivanvorobei/SPIndicator'
77
s.source = { :git => 'https://github.com/ivanvorobei/SPIndicator.git', :tag => s.version }

Sources/SPIndicator/SPIndicatorView.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ open class SPIndicatorView: UIView {
205205
present(duration: self.duration, haptic: haptic, completion: completion)
206206
}
207207

208+
208209
open func present(duration: TimeInterval, haptic: SPIndicatorHaptic = .success, completion: (() -> Void)? = nil) {
209210

210211
if self.presentWindow == nil {
@@ -250,9 +251,16 @@ open class SPIndicatorView: UIView {
250251
iconView.animate()
251252
}
252253
}
254+
255+
safeAreaInsetsObserver = window.observe(\.safeAreaInsets, changeHandler: { [weak self] window, _ in
256+
guard let self = self else { return }
257+
self.center.x = window.frame.midX
258+
self.toPresentPosition(.visible(self.presentSide))
259+
})
253260
}
254261

255262
@objc open func dismiss() {
263+
safeAreaInsetsObserver?.invalidate()
256264
UIView.animate(withDuration: presentAndDismissDuration, delay: 0, usingSpringWithDamping: 1, initialSpringVelocity: 0, options: [.beginFromCurrentState, .curveEaseIn], animations: {
257265
self.toPresentPosition(.prepare(self.presentSide))
258266
if self.presentWithOpacity { self.alpha = 0 }
@@ -272,7 +280,6 @@ open class SPIndicatorView: UIView {
272280
private var whenGesterEndShoudHide: Bool = false
273281

274282
@objc func handlePan(_ gestureRecognizer: UIPanGestureRecognizer) {
275-
276283
if gestureRecognizer.state == .began || gestureRecognizer.state == .changed {
277284
self.gesterIsDragging = true
278285
let translation = gestureRecognizer.translation(in: self)
@@ -395,6 +402,8 @@ open class SPIndicatorView: UIView {
395402
private var spaceBetweenTitles: CGFloat = 1
396403
private var spaceBetweenTitlesAndImage: CGFloat = 16
397404

405+
private var safeAreaInsetsObserver: NSKeyValueObservation?
406+
398407
private var titlesCompactWidth: CGFloat {
399408
if let iconView = self.iconView {
400409
let space = iconView.frame.maxY + spaceBetweenTitlesAndImage

0 commit comments

Comments
 (0)