1

现在我有这个代码:

    _swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swiped)];

[_swipeRecognizer setDirection: UISwipeGestureRecognizerDirectionRight];

[self.superview addGestureRecognizer:_swipeRecognizer];

然后这个:

- (void)swiped {

    // find out where swipe started
    CGPoint loc = [_swipeRecognizer locationInView: self.superview];

    // if swipe was from side of screen and if sidebar is currently closed then open sidebar
    if(!_isOpen && loc.x <= 20)
        [self open];
}

但是,这仅在 self.superview 是可见视图时才有效。我想在 Facebook 应用程序中制作一个侧边栏,无论屏幕上的视图是什么,您都可以从左侧滑入并检测该手势。

4

1 回答 1

1

将手势识别器添加到始终显示的视图中。如果层次结构中有其他视图也附加了手势识别器,则需要向手势添加委托并实现gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:返回 YES(否则手势不会同时操作)。

于 2013-06-08T15:51:33.283 回答