问题
This is Slideout menu using SWRevealController Which run perfectly but can swipe to open but doesn't swipe to close the menu
After adding the library I did few changes but I did know where is the issue.
This is the code in the main viewcontroller
@IBOutlet weak var menuButton:UIBarButtonItem!
override func viewDidLoad() {
super.viewDidLoad()
if self.revealViewController() != nil {
menuButton.target = self.revealViewController()
menuButton.action = "revealToggle:"
self.revealViewController().delegate = self
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
self.revealViewController().delegate = self
var swl = self.revealViewController()
if swl != nil
{
swl.panGestureRecognizer()
swl.tapGestureRecognizer()
}
}
@IBAction func but_back(sender: AnyObject) {
self.navigationController?.interactivePopGestureRecognizer!.delegate = self
self.navigationItem.leftBarButtonItem?.target=self.revealViewController()
self.navigationItem.leftBarButtonItem?.action=Selector("revealToggle:")
self.revealViewController().revealToggle(sender)
self.view.addGestureRecognizer(self.revealViewController().panGestureRecognizer())
}
func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition)
{
if position == FrontViewPosition.Left // if it not statisfy try this --> if revealController.frontViewPosition == FrontViewPosition.Left
{
self.view.userInteractionEnabled = true
revealController.panGestureRecognizer().enabled=true
}
else
{
self.view.userInteractionEnabled = false
revealController.panGestureRecognizer().enabled=false
}
}
回答1:
It appears you are disabling the pan gesture recognizer, along with disabling user interaction on your view, when the the reveal view controller front position is not at the left position in your delegate method implementation for revealController:willMoveToPosition:
from SWRevealViewControllerDelegate
. Therefore, the reveal view controller can only move to a single position. You can change that code to allow the additional positions that you require.
For example, if you comment out this code
func revealController(revealController: SWRevealViewController!, willMoveToPosition position: FrontViewPosition)
{
if position == FrontViewPosition.Left // if it not statisfy try this --> if revealController.frontViewPosition == FrontViewPosition.Left
{
self.view.userInteractionEnabled = true
revealController.panGestureRecognizer().enabled=true
}
else
{
self.view.userInteractionEnabled = false
revealController.panGestureRecognizer().enabled=false
}
}
that should prevent the disabling of the pan gesture unnecessarily.
If you need to disable the reveal view controller pan gesture, I'd suggest using the delegate method revealControllerPanGestureShouldBegin:
from SWRevealViewControllerDelegate
.
来源:https://stackoverflow.com/questions/33025802/swift-swreavealcontroller-cant-swipe-to-close-menu-only-open-with-swipe