我在UIView
监听屏幕上手势的过渡方法时遇到了一些问题。
发生的事情是,如果我向左滑动或向右滑动,它会向我的@selector 方法发送左右滑动信号......这意味着我无法区分滑动。
这是我有问题的代码。我尝试了一些不同的方法,但似乎无法正确处理。
- (void) setupSwipeGestureRecognizer {
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedScreen:)];
swipeGesture.direction = (UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight);
[self.view addGestureRecognizer:swipeGesture];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
self.title = @"Prototype";
//Initalizse the swipe gestuer listener
[self setupSwipeGestureRecognizer];
//alloc and init
self.detailViewA = [[DetailViewController alloc]initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
self.detailViewB = [[DetailViewControllerB alloc]initWithNibName:@"DetailViewControllerB" bundle:[NSBundle mainBundle]];
// set detail View as first view
[self.view addSubview:self.detailViewA.view];
// set up other views
[self.detailViewB.view setAlpha:1.0f];
// Add the view controllers view as a subview
[self.view addSubview:self.detailViewB.view];
// set these views off screen (right)
[self.detailViewB.view setFrame:CGRectMake(320, 0, self.view.frame.size.width, self.view.frame.size.height)];
}
- (void)swipedScreen:(UISwipeGestureRecognizer*)gesture
{
if (gesture.direction = UISwipeGestureRecognizerDirectionLeft) {
NSLog(@"Left");
}
if (gesture.direction = UISwipeGestureRecognizerDirectionRight){
NSLog(@"Right");
}
}