質問

私は、私はシングルタップを検出したいUITextViewを持っています。

これは、私は単にtouchesEnded:withEventをオーバーライドして[[touches anyObject] tapCount] == 1をチェックするといいと思いのように見えます、しかし、このイベントしないでも火ます。

私はこのような4つのイベントをオーバーライドする場合:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    NSLog(@"touchesBegan (tapCount:%d)", touch.tapCount);
    [super touchesBegan:touches withEvent:event];
}

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        NSLog(@"touches moved");
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    NSLog(@"touchesEnded (tapCount:%d)", touch.tapCount);
        [super touchesEnded:touches withEvent:event];
}

-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
        NSLog(@"touches cancelled");
}

私はこのような出力が得られます:

> touchesBegan (tapCount:1)
> touchesCancelled 
> touchesBegan (tapCount:1) 
> touches moved 
> touches moved
> touches moved 
> touchesCancelled

私がtouchesEndedイベントを取得することはありませんようです。

任意のアイデア?

役に立ちましたか?

解決 2

アップデート:私はここに技術を使用して終了: https://devforums.apple.com/message/94569#94569する

私は、これはバグであるかどうかわからないんだけど、UITextViewは、それがこのイベントを飲み込んだ理由は説明するかもしれないので、3.0用のコピーのためのポップアップメニューを行う&ペーストするタッチイベントを利用する必要がありません。

あなたは私に言わせればかなりラメます。

アップデート:私はここにこれについてブログ:のhttp:/ /benscheirman.com/2009/07/detecting-a-tap-on-a-uitextviewする

他のヒント

私もIOS 5.0.1で、動作するように思われるので、同じようUITextviewをサブクラス化。キーは、ちょうど(私が本当に興味がどのようである)touchesEndedない、としてもtouchesBeganを上書きすることです。

@implementation MyTextView


- (id)initWithFrame:(CGRect)frame {
    return [super initWithFrame:frame];
}

- (void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event { 
    // If not dragging, send event to next responder
    if (!self.dragging) 
        [self.nextResponder touchesBegan: touches withEvent:event]; 
    else
        [super touchesBegan: touches withEvent: event];
}

- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event { 
    // If not dragging, send event to next responder
    if (!self.dragging) 
        [self.nextResponder touchesEnded: touches withEvent:event]; 
    else
        [super touchesEnded: touches withEvent: event];
}

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
    if (action == @selector(paste:))
        return NO;
    if (action == @selector(copy:))
        return NO;
    if (action == @selector(cut:))
        return NO;
    if (action == @selector(select:))
        return NO;
    if (action == @selector(selectAll:))
        return NO;
    return [super canPerformAction:action withSender:sender];
}

- (BOOL)canBecomeFirstResponder {
    return NO;
}

- (void)dealloc {
    [super dealloc];
}
あなたはちょうどあなたが許可したくないすべてのアクションのためにNOを返すことができるように

あなたは、canPerformAction:withSender:メソッドをオーバーライドすることで切り取り/コピー/貼り付け]をオフにすることができます。

<のhref = "http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIResponder%5FClass/Reference/Reference.html#//apple%5Fref/occ/instm/を参照してください。 UIResponder / canPerformAction:withSender:」のrel = "nofollowをnoreferrer"> UIResponderのドキュメントに...

うまくいけば、それは食べられてからあなたのタッチを停止します。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top