@@ -140,7 +140,7 @@ class ViewController: UIViewController {
140
140
return true
141
141
}
142
142
143
- dialogController. addAction ( AZDialogAction ( title: " Subscribe " , handler: { [ weak self ] ( dialog) -> ( Void ) in
143
+ dialogController. addAction ( AZDialogAction ( title: " Subscribe " , handler: { ( dialog) -> ( Void ) in
144
144
//dialog.title = "title"
145
145
//dialog.message = "new message"
146
146
//dialog.image = dialog.image == nil ? #imageLiteral(resourceName: "ign") : nil
@@ -348,10 +348,13 @@ class ViewController: UIViewController {
348
348
349
349
dialogController. show ( in: self )
350
350
}
351
-
351
+
352
+ var tableViewDialogController : AZDialogViewController ?
353
+
352
354
func tableViewDialog( ) {
353
355
let dialog = AZDialogViewController ( title: " Switch Account " , message: nil , widthRatio: 1.0 )
354
-
356
+ tableViewDialogController = dialog
357
+
355
358
dialog. showSeparator = false
356
359
357
360
let container = dialog. container
@@ -367,6 +370,7 @@ class ViewController: UIViewController {
367
370
tableView. delegate = self
368
371
tableView. dataSource = self
369
372
tableView. separatorColor = . clear
373
+ //tableView.bouncesZoom = false
370
374
tableView. bounces = false
371
375
372
376
tableView. translatesAutoresizingMaskIntoConstraints = false
@@ -375,6 +379,9 @@ class ViewController: UIViewController {
375
379
tableView. leftAnchor. constraint ( equalTo: container. leftAnchor) . isActive = true
376
380
tableView. rightAnchor. constraint ( equalTo: container. rightAnchor) . isActive = true
377
381
382
+ dialog. gestureRecognizer. delegate = self
383
+ dialog. dismissDirection = . bottom
384
+
378
385
dialog. show ( in: self ) { dialog in
379
386
dialog. contentOffset = self . view. frame. height / 2.0 - dialog. estimatedHeight / 2.0 + 15
380
387
}
@@ -409,6 +416,9 @@ class ViewController: UIViewController {
409
416
}
410
417
411
418
}
419
+
420
+ var shouldDismiss : Bool = false
421
+ var velocity : CGFloat = 0.0
412
422
413
423
}
414
424
@@ -417,7 +427,49 @@ class ViewController: UIViewController {
417
427
extension ViewController : UITableViewDelegate {
418
428
public func tableView( _ tableView: UITableView , didSelectRowAt indexPath: IndexPath ) {
419
429
tableView. deselectRow ( at: indexPath, animated: true )
420
- dismiss ( animated: true , completion: nil )
430
+ tableViewDialogController? . dismiss ( )
431
+ }
432
+
433
+
434
+ func scrollViewDidEndDecelerating( _ scrollView: UIScrollView ) {
435
+ let duration = Double ( 1.0 / abs( velocity) )
436
+ if scrollView. isAtTop {
437
+ if shouldDismiss {
438
+ tableViewDialogController? . animationDuration = duration
439
+ tableViewDialogController? . dismiss ( )
440
+ } else {
441
+ tableViewDialogController? . applyAnimatedTranslation ( - velocity * 35.0 , duration: min ( max ( duration, 0.2 ) , 0.4 ) )
442
+ }
443
+
444
+ }
445
+ }
446
+
447
+ func scrollViewWillEndDragging( _ scrollView: UIScrollView , withVelocity velocity: CGPoint , targetContentOffset: UnsafeMutablePointer < CGPoint > ) {
448
+ shouldDismiss = velocity. y < - 3.0
449
+ self . velocity = velocity. y
450
+ }
451
+
452
+ func scrollViewDidScroll( _ scrollView: UIScrollView ) {
453
+ scrollView. bounces = !scrollView. isAtTop
454
+
455
+ }
456
+ }
457
+
458
+ extension ViewController : UIGestureRecognizerDelegate {
459
+ func gestureRecognizer( _ gestureRecognizer: UIGestureRecognizer , shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer ) -> Bool {
460
+
461
+ let optionalTableView : UITableView ? = otherGestureRecognizer. view as? UITableView
462
+
463
+ guard let tableView = optionalTableView,
464
+ let panGesture = gestureRecognizer as? UIPanGestureRecognizer ,
465
+ let direction = panGesture. direction
466
+ else { return false }
467
+
468
+ if tableView. isAtTop && direction == . down {
469
+ return true
470
+ } else {
471
+ return false
472
+ }
421
473
}
422
474
}
423
475
@@ -498,3 +550,49 @@ class HighlightableButton: UIButton{
498
550
}
499
551
500
552
553
+ public extension UIScrollView {
554
+
555
+ var isAtTop : Bool {
556
+ return contentOffset. y <= verticalOffsetForTop
557
+ }
558
+
559
+ var isAtBottom : Bool {
560
+ return contentOffset. y >= verticalOffsetForBottom
561
+ }
562
+
563
+ var verticalOffsetForTop : CGFloat {
564
+ let topInset = contentInset. top
565
+ return - topInset
566
+ }
567
+
568
+ var verticalOffsetForBottom : CGFloat {
569
+ let scrollViewHeight = bounds. height
570
+ let scrollContentSizeHeight = contentSize. height
571
+ let bottomInset = contentInset. bottom
572
+ let scrollViewBottomOffset = scrollContentSizeHeight + bottomInset - scrollViewHeight
573
+ return scrollViewBottomOffset
574
+ }
575
+
576
+ }
577
+
578
+ public enum PanDirection : Int {
579
+ case up, down, left, right
580
+ public var isVertical : Bool { return [ . up, . down] . contains ( self ) }
581
+ public var isHorizontal : Bool { return !isVertical }
582
+ }
583
+
584
+ public extension UIPanGestureRecognizer {
585
+
586
+ public var direction : PanDirection ? {
587
+ let velocity = self . velocity ( in: view)
588
+ let isVertical = abs ( velocity. y) > abs ( velocity. x)
589
+ switch ( isVertical, velocity. x, velocity. y) {
590
+ case ( true , _, let y) where y < 0 : return . up
591
+ case ( true , _, let y) where y > 0 : return . down
592
+ case ( false , let x, _) where x > 0 : return . right
593
+ case ( false , let x, _) where x < 0 : return . left
594
+ default : return nil
595
+ }
596
+ }
597
+
598
+ }
0 commit comments