From 2158bd738272b5a4e4d46518098870003bc3b6d6 Mon Sep 17 00:00:00 2001 From: Mohamed Afifi Date: Sat, 29 Sep 2018 23:17:02 -0400 Subject: [PATCH] 294: Word pointer relative to safe area insets --- Quran/QuranView.swift | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Quran/QuranView.swift b/Quran/QuranView.swift index ce408231..35960d5c 100644 --- a/Quran/QuranView.swift +++ b/Quran/QuranView.swift @@ -103,6 +103,12 @@ class QuranView: UIView, UIGestureRecognizerDelegate { _pointerTop?.constant = value _pointerParentSize = bounds.size } + private var minX: CGFloat { + return Layout.windowDirectionalSafeAreaInsets.leading + } + private var maxX: CGFloat { + return bounds.width - Layout.windowDirectionalSafeAreaInsets.trailing + } lazy var pointer: UIView = { let imageView = UIImageView() @@ -171,8 +177,11 @@ class QuranView: UIView, UIGestureRecognizerDelegate { super.layoutSubviews() if !pointer.isHidden && _pointerParentSize != bounds.size { setPointerTop(pointer.frame.minY * bounds.height / _pointerParentSize.height) - if pointer.frame.minX != 0 { - _pointerLeft?.constant = bounds.width - pointer.bounds.width + // using bounds.height because it has been rotated but pointer.frame.minX has not + if pointer.frame.minX > bounds.height / 2 { + _pointerLeft?.constant = maxX - pointer.bounds.width + } else { + _pointerLeft?.constant = minX } } } @@ -415,7 +424,7 @@ class QuranView: UIView, UIGestureRecognizerDelegate { layoutIfNeeded() setPointerTop(bounds.height / 4) - _pointerLeft?.constant = 0 + _pointerLeft?.constant = minX UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { self.layoutIfNeeded() }, completion: nil) @@ -460,7 +469,7 @@ class QuranView: UIView, UIGestureRecognizerDelegate { } let finalY = max(10, min(bounds.height - pointer.bounds.height, velocity.y * 0.3 + pointer.frame.minY)) - let finalX = goLeft ? 0 : bounds.width - pointer.bounds.width + let finalX = goLeft ? minX : maxX - pointer.bounds.width let y = finalY - pointer.frame.minY let x = finalX - pointer.frame.minX