0

ポートレートモードとランドスケープモードで「スワイプジェスチャを上下にスワイプ」するアクションを作成したいのですが、初心者なのでできません。助けてください。

これが私のコードです:

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


    }

}

}

4

1 に答える 1

0

これをビューに追加する必要があります:

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


    }


}
}

swipe.direction = UISwipeGestureRecognizerDirectionDown | UISwipeGestureRecognizerDirectionUp; 残念ながら、 を設定するとビット単位の操作が作成され、方向が検出されないため、2 つのスワイプ ジェスチャ認識エンジンを作成する必要があります。

于 2013-07-06T17:13:50.370 に答える