问题
I am implementing ECSlidingViewController
in my app. Everything works fine, when I hit the menu button (UIBar) the left menu slides. But pressing the menu button again does not bring back the current ViewController
.
It works in the sample app, but I cannot find that line of code that brings back the current controller.
Here is the code to show the menu:
- (IBAction)menuButtonTapped:(id)sender {
[self.slidingViewController anchorTopViewToRightAnimated:YES];
}
Now I am looked everywhere for the part of the code that can dismiss the left menu layout but could not find it. It must be burry somewhere...
Github project
How do you get back to the current View Controller by pressing the Menu UIBar
button ?
@Eric opened my eyes on what is performing that event. It seems like the UIPanGestureRecognizer
is the one responsible to redisplay the main screen, unfortunately I couldnt get it to work after implementing that deleguate.
- (UIPanGestureRecognizer *)dynamicTransitionPanGesture {
if (_dynamicTransitionPanGesture) return _dynamicTransitionPanGesture;
_dynamicTransitionPanGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self.transitions.dynamicTransition action:@selector(handlePanGesture:)];
return _dynamicTransitionPanGesture;
}
回答1:
As @eric pointed out, the UIBar
button only displays the menu.
If you want it to dismiss the menu on the same IBAction you will need to add more logic:
- (IBAction)menuButtonTapped:(id)sender {
//Chek the current position
if([self.slidingViewController currentTopViewPosition]==2){
//show menu
[self.slidingViewController anchorTopViewToRightAnimated:YES];
}else{
//Dismiss menu
[self.slidingViewController resetTopViewAnimated:YES];
}
}
回答2:
You are probably looking for the following line:
self.slidingViewController.topViewAnchoredGesture = ECSlidingViewControllerAnchoredGestureTapping | ECSlidingViewControllerAnchoredGesturePanning;
in METransitionsViewController.m in the example TransitionFun project.
This controls how the Top View behaves to gestures while it is anchored to the side. You can refer to Anchored Top Views Gesture for more info.
来源:https://stackoverflow.com/questions/22308531/how-to-go-back-to-current-view-controller