Tôi muốn chặn báo chí dài trên UITextview, nhưng không muốn tắt tùy chọn menu ngữ cảnh cùng một lúc.Làm thế nào để chặn báo chí dài trên UITextView mà không vô hiệu hóa menu ngữ cảnh?
Nếu tôi sử dụng trình nhận dạng cử chỉ trên chế độ xem văn bản, nó sẽ tắt trình đơn ngữ cảnh để tôi sử dụng phương pháp như dưới đây ngay bây giờ.
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
//fire my method here
}
Nhưng, nó chỉ kích hoạt phương thức khi menu ngữ cảnh xuất hiện sau khi người dùng nhấn và giữ một số từ. Vì vậy, khi người dùng nhấn và giữ một khoảng trống, thì chỉ có kính lúp xuất hiện, tôi không thể kích hoạt phương thức đó vào lúc đó.
Có ai có ý tưởng hay hơn không? Cảm ơn!
////// Vấn đề Giải Quyết //////
Nhờ @danh và @Beppe, tôi đã làm cho nó thậm chí với vòi cử chỉ trên UITextView. Tôi muốn hiển thị thanh phông chữ trên chế độ xem văn bản bằng cách nhấn và giữ.
@Đầu tiên, tôi đã phân loại UITextview.
@interface LisgoTextView : UITextView {
BOOL pressing_;
}
@property (nonatomic) BOOL pressing;
@end
@interface LisgoTextView (private)
- (void)longPress:(UIEvent *)event;
@end
@implementation LisgoTextView
@synthesize pressing = pressing_;
//--------------------------------------------------------------//
#pragma mark -- Long Press Detection --
//--------------------------------------------------------------//
- (void)longPress:(UIEvent *)event {
if (pressing_) {
//post notification to show font edit bar
NSNotification *fontEditBarNotification = [NSNotification notificationWithName:@"fontEditBarNotification"
object:nil userInfo:nil];
[[NSNotificationCenter defaultCenter] postNotification:fontEditBarNotification];
}
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
[self performSelector:@selector(longPress:) withObject:event afterDelay:0.7];
pressing_ = YES;
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
pressing_ = NO;
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
pressing_ = NO;
}
@Tôi đã sử dụng độ trễ để giải quyết xung đột với cử chỉ nhấn mà tôi đã triển khai trên UITextView.
- (void)tapGestureOnTextView:(UITapGestureRecognizer *)sender {
//cancel here if long press was fired first
if (cancelTapGesture_) {
return;
}
//don't fire show font bar
cancelShowFontBar_ = YES;
[self performSelector:@selector(enableShowFontBar) withObject:nil afterDelay:1.0];
//method here
}
- (void)showFontEditBar {
//cancel here if tap gesture was fired first
if (cancelShowFontBar_) {
return;
}
if (fontEditBarExists_ == NO) {
//method here
//don't fire tap gesture
cancelTapGesture_ = YES;
[self performSelector:@selector(enableTapGesture) withObject:nil afterDelay:1.0];
}
}
- (void)enableTapGesture {
cancelTapGesture_ = NO;
}
- (void)enableShowFontBar {
cancelShowFontBar_ = NO;
}
ahahah: D Banzai cho "tâm trí tuyệt vời" !!! – Beppe
Mặc dù tôi vẫn đang đấu tranh để giải quyết xung đột với tapGesture tôi đã thực hiện trên UITextview, đây là câu trả lời cho câu hỏi của tôi. Cảm ơn nhiều. –
Tôi đã làm cho nó với cuộc xung đột để viết các lỗ hổng làm việc trên phần trả lời. –