Ios LS模式的滑动手势&;肖像模式

Ios LS模式的滑动手势&;肖像模式,ios,swipe,gesture,Ios,Swipe,Gesture,我想在纵向和横向模式下创建一个动作“上下滑动手势”,但我是新手,我不能这样做,你能帮我吗 这是我的密码: -(void)swipeToggle:(id)sender { if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UI

我想在纵向和横向模式下创建一个动作“上下滑动手势”,但我是新手,我不能这样做,你能帮我吗

这是我的密码:

-(void)swipeToggle:(id)sender {
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight) {
    if (UISwipeGestureRecognizerDirectionUp){

         NSLog(@"if gesture up - LS");


    } else if (UISwipeGestureRecognizerDirectionDown) {

        NSLog(@"else if gesture down - LS");

     }

}
else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait) {
    if (UISwipeGestureRecognizerDirectionDown) {

        NSLog(@"if gesture down - PT");

    }
    else if (UISwipeGestureRecognizerDirectionUp) {

        NSLog(@"else if gesture up - PT");


    }

}

}

您需要将其添加到视图中:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UISwipeGestureRecognizer *swipe1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToggle:)];

swipe1.direction = UISwipeGestureRecognizerDirectionUp ;
[self.view addGestureRecognizer:swipe1];
[swipe1 release];

UISwipeGestureRecognizer *swipe2 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeToggle:)];

swipe2.direction = UISwipeGestureRecognizerDirectionDown ;
[self.view addGestureRecognizer:swipe2];
[swipe2 release];
}
然后切换:

-(void)swipeToggle:(UISwipeGestureRecognizer *)sender
{ 
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeLeft || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationLandscapeRight)
{
    if (sender.direction ==  UISwipeGestureRecognizerDirectionUp){

        NSLog(@"if gesture up - LS");


    } else if (sender.direction ==  UISwipeGestureRecognizerDirectionDown) {

        NSLog(@"else if gesture down - LS");

    }

}
else if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait || [[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortraitUpsideDown)
{

    if (sender.direction == UISwipeGestureRecognizerDirectionDown)
    {

        NSLog(@"if gesture down - PT");

    }
    else if ( sender.direction == UISwipeGestureRecognizerDirectionUp)
    {

        NSLog(@"else if gesture up - PT");


    }


}
}
不幸的是,您需要创建2个滑动手势识别器,因为设置
swipe.direction=uiswipgesturecognizerDirectionDown | uiswipgesturecognizerDirectionUp

将创建按位操作,并且不会检测到方向。

没问题!一点点,你就会成功。