现在我有这个代码:
_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 应用程序中制作一个侧边栏,无论屏幕上的视图是什么,您都可以从左侧滑入并检测该手势。