2017-01-27 12 views
0

私はのViewControllerのナビゲーションコントローラを持っているので、私はので、このdoesntのは、ビュー上でスワイプを無効にするには、このスワイプジェスチャー認識プログラムは方向を検出できません。

UISwipeGestureRecognizer *noRightShiftForVolume = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleVolumeViewSwipe1:)]; 
    [self.circleProgressBar addGestureRecognizer:noRightShiftForVolume]; 

のようなジェスチャー認識装置を使用していた場合。 しかし、このように宣言するとうまくいくが、スワイプの方向はわからない。

UIPanGestureRecognizer *noRightShiftForVolume = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleVolumeViewSwipe1:)]; 
    [self.circleProgressBar addGestureRecognizer:noRightShiftForVolume]; 

関数のimplemenationは次のようである:ナビゲーションコントローラ BOOL eliminateSwipeで

- (void)handleVolumeViewSwipe1:(UISwipeGestureRecognizer *)sender 
{ 

    if (sender.state == UIGestureRecognizerStateBegan) { 
     [applicationControllerShared() enableSwipe:NO]; 
     NSLog(@"good karens"); 

     if(UISwipeGestureRecognizerDirectionLeft){ 
     CATransition *animation = [CATransition animation]; 
     [animation setType:kCATransitionPush]; 
     [animation setSubtype:kCATransitionFromRight]; 
     [animation setDuration:0.50]; 
     [animation setTimingFunction: 
     [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; 
     [_circleProgressBar.layer addAnimation:animation forKey:kCATransition]; 
     NSLog(@"Swipe Left"); 
     } 

     if(UISwipeGestureRecognizerDirectionRight){ 
      NSLog(@"Swipe Right"); 
     } 
    } 

    if (sender.state == UIGestureRecognizerStateEnded) 
    { 
     [applicationControllerShared() enableSwipe:YES]; 
     NSLog(@"good karens 110"); 
    } 
} 

。このような eliminateSwipe機能ルック:

-(void) enableSwipe: (BOOL) state 
{ 
    eliminateSwipe = !state; 
} 

がスワイプ機能を有効にするには、ナビゲーションコントローラのスワイプを無効にし、私の機能handleVolumeViewSwipe1を実現するために力を与えます。 私は左右のスワイプを検出して機能を実行したい円の進捗バーを持っています。どのように私はそれを行うことができますどのような手掛かり。

私はこのSwipeGestureRecognizerDirectionをViewDidLoadとViewDidAppearで実装しようとしましたが、ナビゲーションコントローラのスワイプ機能のために働いていません。

これはUIPanGestureRecognizerの助けを借りて解決され、あなたがpopGestureを停止するUINavigationControllerDelegateのデリゲートを適用する必要があり、私のexprienceを1としてスワイプは、次のコード

if (sender.state == UIGestureRecognizerStateBegan) { 
     [applicationControllerShared() enableSwipe:NO]; 
     CGPoint velocity = [sender velocityInView:_circleProgressBar]; 

     if(velocity.x < 0) 
     { 
      NSLOG(@"swipe left"); 
}else{ 
NSLOG(@"swipe right");} 
} 
+0

ジェスチャーの 'noRightShiftForVolume.direction'プロパティを設定しましたか? – CodeChanger

+0

はい、それはまったく役に立ちません。スワイプは、ナビゲーションコントローラ –

+0

に私を連れて行くので、それはそのviewController右から飛び出すでしょうか? – CodeChanger

答えて

1

で検出することができます。

手順1:プロトコルを.hファイルで確認します。(オプションステップ)

@interface ViewController : UIViewController<UINavigationControllerDelegate> 

ステップ2:viewDidLoadにデリゲートを設定します。(オプションステップ)

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    self.navigationController.interactivePopGestureRecognizer.delegate = self; 
} 

ステップ3:そして&過去のVCにviewWillDisApperでジェスチャーを無効にします。(必須ステップ)

self.navigationController.interactivePopGestureRecognizer.enabled = YES; 

希望すると、これが役に立ちます。

+0

非常に多くのCodeChangerありがとうございますが、この1つは既に適用されており、まったく動作していません。 –

+0

どこにこれを適用しましたか?以前の画面または同じジェスチャービューの画面では? – CodeChanger

+0

私はそれを前に適用して、私は今も試みました。 Didnt work。スワイプの方向を検出する必要があります。UITapGestureは正常に動作していますが、理由はわかりません。UISwipeGestureDirection –

関連する問題