-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from tamanyan/feature-swipe-gesture
Enable page swiping along with UITableView scrolling
- Loading branch information
Showing
21 changed files
with
119 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// PanBlockGestureRecognizer.swift | ||
// SwiftPageMenu | ||
// | ||
// Created by Taketo Yoshida on 11/1/29 H. | ||
// Copyright © 29 Heisei Tamanyan. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
|
||
class PanBlockGestureRecognizerDelegate: NSObject, UIGestureRecognizerDelegate { | ||
|
||
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool { | ||
return true | ||
} | ||
} | ||
|
||
class PanBlockGestureRecognizer: UIPanGestureRecognizer { | ||
|
||
fileprivate var panBlockGestureRecognizerDelegate = PanBlockGestureRecognizerDelegate() | ||
|
||
var inView: UIView? | ||
|
||
var isEnded: Bool = false | ||
|
||
var beginPanLocation: CGPoint = .zero | ||
|
||
var endPanLocation: CGPoint = .zero | ||
|
||
init(in view: UIView) { | ||
super.init(target: self, action: #selector(self.performAction(sender:))) | ||
|
||
self.inView = view | ||
self.delegate = self.panBlockGestureRecognizerDelegate | ||
} | ||
|
||
func performAction(sender: UIGestureRecognizer) { | ||
guard let panGesture = sender as? UIPanGestureRecognizer else { return } | ||
let state = panGesture.state | ||
let panLocation = panGesture.location(in: self.inView) | ||
let permissionVertical: CGFloat = 10 | ||
let swipeStroke: CGFloat = 10 | ||
|
||
if state == .began { | ||
self.beginPanLocation = panLocation | ||
self.isEnded = false | ||
} else if state == .changed && self.isEnded == false { | ||
self.endPanLocation = panLocation | ||
let moveX = self.endPanLocation.x - self.beginPanLocation.x | ||
let moveY = self.endPanLocation.y - self.beginPanLocation.y | ||
let absX = abs(moveX) | ||
let absY = abs(moveY) | ||
|
||
if absY < permissionVertical && absX > swipeStroke { | ||
panGesture.setValue(UIGestureRecognizerState.cancelled.rawValue, forKey: "state") | ||
self.isEnded = true | ||
} else if absY > permissionVertical { | ||
self.isEnded = true | ||
panGesture.setValue(UIGestureRecognizerState.ended.rawValue, forKey: "state") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters