1

我正在为我的应用程序使用John Lluch 的 SWRevealViewController 项目,但我遇到了一个小问题,我似乎无法弄清楚。

我正在使用 SWRevealViewController 从应用程序中的任何位置访问我的应用程序选项菜单,只需向右滑动,主视图就会滑动以显示其背后的菜单。

这由添加到主视图的滑动手势识别器处理。为了改善用户体验,我创建了一个按钮来在主视图被滑开时覆盖它,因此用户关闭菜单所需要做的就是点击正在显示的视图的一小部分或抓住视图并将其拉出背部。

它工作得很好,除了我的一个视图,其中大部分视图是 UIScrollView。为了让它工作,我必须将手势识别器添加到 UIScrollView 以及超级视图。但是由于某种原因,一旦视图被滑开,滑动手势识别器就会停止响应。但这只会发生在大部分屏幕是滚动视图的视图上,因此用户抓取以拉回屏幕的是滚动视图。

希望这是可以理解的。你们可以照亮的任何光线都会非常有帮助。

-(void)viewDidAppear:(BOOL)animated {
    // so the user can tap the button to show the menu
    [menuButton addTarget:self.revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];

    // so the user can swipe to show the menu
    [self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];

    // so the user can swipe the scrollview to show the menu
    [mainScrollView addGestureRecognizer:self.revealViewController.panGestureRecognizer];

    self.revealViewController.delegate = self;
}

- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position {
    if (position == FrontViewPositionRight) {
        //create the button so the use can tap to close the menu
        returnButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

        [returnButton addTarget:self.revealViewController action:@selector(revealToggle:) forControlEvents:UIControlEventTouchUpInside];

        [self.view addSubview:returnButton];
    } else {
        [returnButton removeFromSuperview];
        returnButton = nil;
    }
}

在此处输入图像描述

4

1 回答 1

0

所以我刚刚发现这个问题已经在 SWRevealViewController 项目中得到解决。这篇文章为我指明了正确的方向。他们添加了一个点击手势识别器,它具有我使用动态创建的按钮创建的行为。

添加

[self.view addGestureRecognizer:self.revealViewController.tapGestureRecognizer];

消除了对按钮的需要,从而允许视图响应两个识别器。

于 2015-01-23T08:19:00.543 回答