- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"touchesBegan");
//test
UITouch *touch = [event allTouches] anyObject];
if ([touch tapCount] == 2) {
NSLog (@"tapcount 2");
[self.textview becomeFirstResponder];
}
else if ([touch tapCount] == 1) {
NSLog (@"tapcount 1");
[self.textview becomeFirstResponder];
[self.view performSelector:@selector(select:)];
}
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesBegan:touches withEvent:event];
NSLog(@"touchesMoved");
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"****touchesEnded");
[self.nextResponder touchesEnded: touches withEvent:event];
NSLog(@"****touchesEnded");
[super touchesEnded:touches withEvent:event];
NSLog(@"****touchesEnded");
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesCancelled:touches withEvent:event];
NSLog(@"touchesCancelled");
}
我要上一個UITextView,這是該代碼的TextView一次敲擊時,模擬兩個水龍頭。但是,當我在textview上點擊一次或兩次時,我不會從一個和兩個水龍頭中獲得NSLog,只能在它之外。我應該怎麼做才能使它工作?
首先,這段代碼必須在自定義的UITextView子類中工作,並且可能會干擾正常的操作。其次,你的意思是「我想在UITextView上敲擊一次時模擬兩次敲擊」,我的意思是爲了什麼目的? – NJones
@NJones我想給用戶一個選項來選擇一個或兩個特定功能的水龍頭。我想要模擬兩個水龍頭來獲取選定的文本,並使其只有一個水龍頭用戶,如果他們選擇此選項。在UITextView上點擊一次時是否可以強制執行兩次敲擊? bensnider的解決方案完美地工作。但如何模擬兩個水龍頭? – wagashi