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");
}
}