我有一些麻煩與被監聽在屏幕上比劃我UIView
過渡方法。設置SwipeGestureRecognizer爲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");
}
}
我認爲你必須爲每個方向單獨識別 - 看看[爲UISwipeGestureRecognizer設置方向(http://stackoverflow.com/questions/ 3319209 /設置方向換uiswipegesturerecognizer)。 –
好吧,所以我剛剛結束這樣做...不知道它是否是最好的解決方案,但它的挑戰性工作.. –