6
我正在嘗試將UILongPressGestureRecognizer
添加到頁面上的一個UITextField,但長按UiTextField時它不會調用選擇器方法。 我將它添加到UItextField但是,當我長按TextField但在場上顯示放大鏡時,它不調用Selector方法。如何將UILongPressGestureRecognizer添加到UITextField?
[self.tfCustomerStreet addGestureRecognizer:LongPressgesture];
但它工作正常,並調用選擇器方法,如果我將它添加到視圖。在viewDidLoad中
UILongPressGestureRecognizer *LongPressgesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPressgesture:)];
[LongPressgesture setMinimumPressDuration:2.0];
[[self view] addGestureRecognizer:LongPressgesture];
初始化代碼。
// Long press gesture reconizer
- (void)LongPressgesture:(UILongPressGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateEnded) {
NSLog(@"Long press Ended .................");
}
else {
NSLog(@"Long press detected .....................");
}
}
請告訴我如何使它與UITextField一起工作。
感謝Malek ..它開始致力於清除[LongPressgesture setMinimumPressDuration:2.0];但如果添加您提到的代碼則不起作用。但問題解決..謝謝:) – Azhar
歡迎..但第二sloution是否添加了'UIGestureRecognizerDelegate'在.h? –
還需要設置'LongPressgesture.delegate = self;' –