Tôi đang sử dụng lớp UILongPressGestureRecognizer để xử lý nếu một mục đang được chọn.UILongPressGestureRecognizer ngừng xử lý mà không cần dừng lại chạm vào
Logic như sau: Báo chí người dùng trong 1 giây một mục (lớp con UIView). Khi cử chỉ được phát hiện, mục được tô sáng và di chuyển.
Người dùng phải di chuyển mục này trên màn hình mà không cần dừng chạm vào nó.
Sự cố tôi đang gặp phải là cử chỉ được nhận dạng của cử chỉ bóngBan/Di chuyển/Đã kết thúc cần thiết cho hạng mục để sắp xếp chuyển động.
Tôi đã cố gắng xóa cử chỉ được nhận diện một lần được phát hiện và mục được chọn. Nhưng vẫn gửi tin nhắn đến tay cầm của cử chỉ thay vì phương thức chạm cuộc gọi.
Bất cứ ai biết cách nào để dừng "nghe" trình nhận dạng cử chỉ mà không để lại ngón tay của màn hình?
Cảm ơn.
Đây mã:
-(void)addGestures
{
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = iItemLongPressTime;
[self addGestureRecognizer:longPress];
[longPress release];
}
- (void)handleLongPress:(UILongPressGestureRecognizer*)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"Long press Ended");
}
else {
if (self.isSelected) return;
if ([delegate respondsToSelector:@selector(singleTouch:)])
[delegate singleTouch:self];
[self removeGestureRecognizer:[self.gestureRecognizers objectAtIndex:0]];
NSLog(@"Long press detected.");
}
}
Như bạn có thể thấy trong các chi nhánh khác các đại biểu kêu gọi cho phép tất cả các thủ tục để đánh dấu mục này theo sự lựa chọn, và chỉ sau khi loại bỏ bên nhận.
Tôi đang thiếu gì?
--EDIT--
Xong! Công trình này:
#pragma mark Gesture Functions
-(void)addGestures
{
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]
initWithTarget:self
action:@selector(handleLongPress:)];
longPress.minimumPressDuration = iItemLongPressTime;
[self addGestureRecognizer:longPress];
[longPress release];
}
- (void)handleLongPress:(UILongPressGestureRecognizer*)sender {
if (sender.state == UIGestureRecognizerStateEnded) {
NSLog(@"Long press Ended");
}
else {
NSLog(@"Long press detected.");
if (self.isSelected) return;
if ([delegate respondsToSelector:@selector(singleTouch:)])
[delegate singleTouch:self];
[sender removeTarget:self action:@selector(handleLongPress:)];
sender.enabled = NO;
[self removeGestureRecognizer:sender];
}
}
Kính trọng!
hãy thử mô tả chi tiết câu hỏi của bạn –
Tôi đã thử gửi để xóa phương thức người gửi làm thông số nhưng vẫn không hoạt động. – NemeSys
tôi đã chỉnh sửa câu trả lời của mình ... –