Tôi đang tạo một ứng dụng iPhone tương tự như ứng dụng Tin nhắn đi kèm trên điện thoại. Tôi chỉ thiết lập khả năng sao chép tin nhắn thông qua UIMenuController, nhưng nếu bàn phím đang hiển thị và ai đó cố gắng sao chép một tin nhắn, bàn phím sẽ biến mất (có lẽ là vì [cell becomeFirstResponder];
của tôi nơi cell
là ô thông báo đang được sao chép).Hiển thị UIMenuController mất bàn phím
Có cách nào để hiển thị thông báo Sao chép mà không làm mất bàn phím không?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:
(NSIndexPath *)indexPath {
//...other cell setup stuff...
UILongPressGestureRecognizer *longPressGesture =
[[UILongPressGestureRecognizer alloc]
initWithTarget:self action:@selector(showCopyDialog:)];
[cell addGestureRecognizer:longPressGesture];
return cell;
}
- (void)showCopyDialog:(UILongPressGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateBegan)
{
ConvoMessageCell *cell = (ConvoMessageCell *)[gesture view];
NSIndexPath *indexPath = [self.tblConvo indexPathForCell:cell];
UIMenuController *theMenu = [UIMenuController sharedMenuController];
[cell becomeFirstResponder];
[theMenu setTargetRect:CGRectMake(menuX, menuY, 100, 100) inView:cell];
[theMenu setMenuVisible:YES animated:YES];
}
}
Điều này có thể hoạt động, nhưng MenuController sẽ được đặt ngay tại trung tâm ngang của ô. –