2016-03-25 10 views
0

スクロールビューのほとんどのスペースを占める大きなボタンを持つ垂直UIScrollViewがあります。ボタンをタップしたときサブクラス化されたUIScrollViewはボタン内のタッチを検出しますが、それ以外の場合はユーザーのやりとりに反応しません。

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view 
{ 
    static int count = 0; 
    count++; 
    NSLog(@"calling this function 2"); 
    NSLog(@"count = %d", count); 
    UITouch *touch = [touches anyObject]; 

    if(touch.phase == UITouchPhaseMoved) 
    { 
     NSLog(@"UITouchPhaseMoved so returning no"); 
     return NO; 
    } 


    else 
    { 
     NSLog(@"returning super"); 
     NSLog(@"returning whatever this value is %d 0/1", [super touchesShouldBegin:touches withEvent:event inContentView:view]); 
     [super touchesShouldBegin:touches withEvent:event inContentView:view]; 
     return [super touchesShouldBegin:touches withEvent:event inContentView:view]; 
    } 
} 

私は私のアプリを実行し、この上記の関数が呼び出されるが、機能:このような理由から、私はこの記事ios 8 - buttons in horizontal scroll view intercepting pan event - scroll does not work次スクロールビューのサブクラス)と、以下のクラスのメソッドをオーバーライドしなければなりませんでしたボタンの内側または外側で、スクロールビューのどこにでもドラッグすると呼び出されません。そして、私がドラッグしようとする場所に関係なく、スクロールビューはスクロールしません。

ここで(それはIBで設定です)スクロールビューに関連するすべての私のコードです:

  smallView.scrollEnabled = YES; 
      smallView.contentSize = CGSizeMake(smallView.frame.size.width, smallView.frame.size.height*1.4); 
      smallView.delegate = self; 

そして、ここでは問題とケース内のボタンに関連するコードです:

NSArray *buttonsArray = @[button1, button2, button3, button4, button5]; 
for (int i = 0; i < [buttonsArray count]; i++) { 
    UIButton *button = buttonsArray[i]; 
    button.tag = i+1; 
    [button addTarget:self action:@selector(p_motivationButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; 
    button.titleLabel.lineBreakMode = NSLineBreakByWordWrapping; 
    button.titleLabel.textAlignment = NSTextAlignmentCenter; 
} 

なぜですスクロール表示はスクロールせず、touchesShouldBeginとも呼ばれません。

+0

Y touchphaseが移動されたときにuが何を返しますか? –

+0

@TejaNandamuriわかりませんが、それは変わる可能性がありますが、その機能は決して論理のその枝に入ることはありません。 – helloB

+0

どこに触れた移動メソッドを実装しましたか?タッチ開始メソッドは、タッチされた移動イベントを傍受することはできません。タッチイベントの開始点のみを検出します。 –

答えて

0

サブクラスUIScrollViewと次のようにtouchesShouldCancelInContentView()をオーバーライド:

override func touchesShouldCancelInContentView(view: UIView) -> Bool { 
    if let _ = view as? UIControl { 
     return true 
    } 
    else { 
     return super.touchesShouldCancelInContentView(view) 
    } 
} 
関連する問題