使用ECSlidingViewController和TableView

3
我正在我的应用程序中使用ECSlidingViewController,它包含了自己的GestureRecognizer,长这样子:
[self.view addGestureRecognizer:self.slidingViewController.panGesture];

这段代码会阻止TableView的滚动。当我删除了这行后,滚动就正常了。我的做法有什么问题吗?

注意:TableView是导航控制器(Navigation Controller)的一部分。我正在使用故事板(StoryBoards)。

3个回答

11
您需要将 UIGestureRecognizer 添加到 UINavigationController 的视图中,而不是添加到 UITableView 中。
一种方法是创建一个 UINavigationController 子类,它处理手势识别器的创建以及 ECSlidingViewController 的 underLeft(或 underRight)视图控制器的实例化:
// MyNavigationController.h
@interface MyNavigationController : UINavigationController

@end

// MyNavigationController.m
@implementation MyNavigationController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    if (![self.slidingViewController.underLeftViewController isKindOfClass:[MyLeftMenuViewController class]]) {
        self.slidingViewController.underLeftViewController  = [self.storyboard instantiateViewControllerWithIdentifier:@"MenuViewController"];
    }

    [self.view addGestureRecognizer:self.slidingViewController.panGesture];
}

@end

打开Storyboard编辑器,选中导航控制器,并将Identity Inspector的Custom Class字段设置为MyNavigationController(而不是默认的UINavigationController)。


6
我尝试了你建议的方法,但是将手势识别器插入UINavigationController的子类中并没有起作用。奇怪的是,将理论上相当的内容放置在...
[self.navigationController.view addGestureRecognizer:self.slidingViewController.panGesture];

在TableViewController中,viewWillAppear:方法能够达到目的。

0
尝试
[self.parentView.view addGestureRecognizer:self.slidingViewController.panGesture];

在TableViewController的viewWillAppear方法中


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接