2016-04-16 9 views
0

UIButtonをタッチすると、touchesBegan,touchesMovedおよびtouchesEndedメソッドは呼び出されません。私は、連続したタッチが起こったときにイベントを実行し、タッチが終了したときにイベントをキャンセルしたい。touchesBeganとtouchesEndedはUIButtonで呼び出されません

+1

[touchesbegan /移動/ Xcodeの6.3で動作していない終了]の可能な重複(http://stackoverflow.com/questions/29552897/touchesbegan-moved-ended-not-working-with-xcode-6- 3) – kb920

+0

ボタンとすべてのスーパービューで 'userInteractionEnabled'がtrueに設定されていることを確認します。ほとんどの 'UIViews'ではデフォルトでtrueですが、いくつかの例外があります。 – Hamish

+0

uibuttonの場合これは呼び出されません –

答えて

0

UIButtonコントロールイベントを使用して、UIButtonタッチスタートとタッチエンドを追跡できます。

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    [self.button addTarget:self action:@selector(touchStarted:) forControlEvents:UIControlEventTouchDown]; 
    [self.button addTarget:self action:@selector(touchEnded:) forControlEvents:UIControlEventTouchUpInside]; 
    [self.button addTarget:self action:@selector(touchEnded:) forControlEvents:UIControlEventTouchUpOutside]; 
} 


- (void)touchStarted:(id)sender { 
    NSLog(@"Touch started"); 
} 

- (void)touchEnded:(id)sender { 
    NSLog(@"Touch ended"); 
} 
関連する問題