3

我在我的应用程序中使用ECSlidingViewController,它包含的拥有GestureRecognizer看起来像:

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

它阻止了 TableView 的滚动。当我删除该行滚动工作正常。我的方法有什么问题?

注意:TableView是导航控制器的一部分。我正在使用StoryBoards

4

3 回答 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 Editor,选择导航控制器并将 Identity Inspector 的 Custom Class 字段设置为MyNavigationController(而不是默认值UINavigationController)。

于 2013-01-26T03:24:10.217 回答
6

我尝试了您建议的方法,但是在 UINavigationController 的子类中插入手势识别器不起作用。奇怪的是,把理论上等价的

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

在 TableviewControllerviewWillAppear:方法中可以代替。

于 2013-07-05T15:29:33.817 回答
0

尝试

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

在 viewWillAppear 上的 TableViewController

于 2013-08-08T10:24:54.867 回答