@@ -32,20 +32,19 @@ class UIFloatMenu {
3232 static private var animationDuration : TimeInterval = 0.3
3333
3434 // Delegate
35- static var closeDelegate : UIFloatMenuCloseDelegate ?
36- static var textFieldDelegate : UIFloatMenuTextFieldDelegate ?
35+ static public var delegate = Delegates ( )
3736
3837 // Queue
3938 static private var queue = [ UIFloatMenuQueue] ( )
4039
4140 //MARK: - Show
4241 static func show( _ vc: UIViewController , actions: [ UIFloatMenuAction ] ) {
4342 if queue. count <= maxView {
44- let correct = correctPosition ( viewConfig. presentation)
43+ let correct = UIFloatMenuHelper . correctPosition ( viewConfig. presentation)
4544 let id = UIFloatMenuID . genUUID ( queue. count)
4645
4746 let menuView = UIFloatMenuView . init ( items: actions, vc: currentVC, header: headerConfig, config: viewConfig,
48- closeDelegate : closeDelegate , textFieldDelegate : textFieldDelegate )
47+ delegate : delegate )
4948 menuView. tag = id
5049
5150 vc. view. addSubview ( menuView)
@@ -137,38 +136,13 @@ class UIFloatMenu {
137136 static private func panChanged( _ gesture: UIPanGestureRecognizer ) {
138137 let view = gesture. view!
139138 let translation = gesture. translation ( in: gesture. view)
140- let velocity = gesture. velocity ( in: gesture. view)
141139
142- var translationAmount = translation. y >= 0 ? translation. y : - pow( abs ( translation. y) , 0.7 )
140+ var translationAmount = translation. y >= 0 ? translation. y : - pow( abs ( translation. y) , 0.5 )
143141
144142 let rubberBanding = true
145143
146144 if !rubberBanding && translationAmount < 0 { translationAmount = 0 }
147145
148- if gesture. direction ( in: view) == . Up && gesture. view!. frame. origin. y < initY. last! {
149- if let UIFloatMenu = currentVC. view. viewWithTag ( queue. last!. uuid!) {
150- let backTranslationAmount = translation. y >= 0 ? translation. y : - pow( abs ( translation. y) , 0.6 )
151- UIFloatMenu . transform = CGAffineTransform ( translationX: 0 , y: backTranslationAmount)
152- }
153- }
154-
155- if gesture. direction ( in: view) == . Down {
156- for order in 0 ..< queue. count- 1 {
157- if let UIFloatMenu = currentVC. view. viewWithTag ( queue [ order] . uuid) {
158- if velocity. y > 180 {
159- UIView . animate ( withDuration: 0.2 , animations: {
160- UIFloatMenu . transform = . identity
161- } )
162- } else {
163- if UIFloatMenu . frame. origin. y <= initY [ order] {
164- let backTranslationAmount = translation. y >= 0 ? translation. y : - pow( abs ( translation. y) , 0.6 )
165- UIFloatMenu . transform = CGAffineTransform ( translationX: 0 , y: backTranslationAmount)
166- }
167- }
168- }
169- }
170- }
171-
172146 view. transform = CGAffineTransform ( translationX: 0 , y: translationAmount)
173147 }
174148
@@ -186,33 +160,9 @@ class UIFloatMenu {
186160 }
187161 }
188162
189- // MARK: - correctPosition()
190- static public func correctPosition( _ position: UIFloatMenuPresentStyle ) -> UIFloatMenuPresentStyle {
191- let device = UIDevice . current. userInterfaceIdiom
192-
193- if device == . pad {
194- let layout = Layout . determineLayout ( )
195-
196- if layout == . iPadOneThirdScreen {
197- if case . center = position {
198- return . center
199- }
200- return . default
201- }
202- return position
203- } else if device == . phone {
204- if case . center = position {
205- return . center
206- }
207- return . default
208- } else {
209- return position
210- }
211- }
212-
213163 // MARK: - closeMenu()
214164 static private func closeMenu( _ menuView: UIView ) {
215- let correct = correctPosition ( viewConfig. presentation)
165+ let correct = UIFloatMenuHelper . correctPosition ( viewConfig. presentation)
216166 let appRect = UIApplication . shared. windows [ 0 ] . bounds
217167 let topPadding = UIFloatMenuHelper . getPadding ( . top)
218168
@@ -268,9 +218,10 @@ class UIFloatMenu {
268218 }
269219
270220 menuView. alpha = 0
271- UIView . animate ( withDuration : animationDuration, animations : {
221+ let animator = UIViewPropertyAnimator ( duration : animationDuration, dampingRatio : 1.0 ) {
272222 menuView. alpha = 1
273- } )
223+ }
224+ animator. startAnimation ( )
274225 break
275226 case . default:
276227 if iPad_window_width != 0 {
@@ -279,9 +230,10 @@ class UIFloatMenu {
279230 if animation {
280231 menuView. center = CGPoint ( x: appRect. width/ 2 , y: getPrepare)
281232
282- UIView . animate ( withDuration : animationDuration, delay : 0 , options : . transitionCurlUp , animations : {
233+ let animator = UIViewPropertyAnimator ( duration : animationDuration, dampingRatio : 1.0 ) {
283234 menuView. center. y = getShow
284- } )
235+ }
236+ animator. startAnimation ( )
285237 } else {
286238 menuView. center = CGPoint ( x: appRect. width/ 2 , y: getShow)
287239 }
@@ -293,9 +245,10 @@ class UIFloatMenu {
293245
294246 if animation {
295247 menuView. alpha = 0
296- UIView . animate ( withDuration : animationDuration, animations : {
248+ let animator = UIViewPropertyAnimator ( duration : animationDuration, dampingRatio : 1.0 ) {
297249 menuView. alpha = 1
298- } )
250+ }
251+ animator. startAnimation ( )
299252 }
300253 break
301254 case . leftDown( let overToolBar) :
@@ -304,9 +257,10 @@ class UIFloatMenu {
304257
305258 if animation {
306259 menuView. alpha = 0
307- UIView . animate ( withDuration : animationDuration, delay : 0 , options : . curveEaseOut , animations : {
260+ let animator = UIViewPropertyAnimator ( duration : animationDuration, dampingRatio : 1.0 ) {
308261 menuView. alpha = 1
309- } )
262+ }
263+ animator. startAnimation ( )
310264 }
311265 break
312266 case . rightUp( let overNavBar) :
@@ -318,9 +272,10 @@ class UIFloatMenu {
318272
319273 if animation {
320274 menuView. alpha = 0
321- UIView . animate ( withDuration : animationDuration, animations : {
275+ let animator = UIViewPropertyAnimator ( duration : animationDuration, dampingRatio : 1.0 ) {
322276 menuView. alpha = 1
323- } )
277+ }
278+ animator. startAnimation ( )
324279 }
325280 }
326281 break
@@ -333,9 +288,10 @@ class UIFloatMenu {
333288
334289 if animation {
335290 menuView. alpha = 0
336- UIView . animate ( withDuration : animationDuration, animations : {
291+ let animator = UIViewPropertyAnimator ( duration : animationDuration, dampingRatio : 1.0 ) {
337292 menuView. alpha = 1
338- } )
293+ }
294+ animator. startAnimation ( )
339295 }
340296 }
341297 break
0 commit comments