我正在製作一個類似於手機上的Messages應用程序的iphone應用程序。我只是設置了通過UIMenuController複製郵件的功能,但是如果鍵盤顯示並且有人試圖複製郵件,鍵盤就會消失(大概是因爲我的[cell becomeFirstResponder];
,其中cell
是被複制的郵件單元格)。顯示UIMenuController丟失鍵盤
有沒有辦法顯示覆制信息而不會丟失鍵盤?
- (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];
}
}
這可能工作,但MenuController將被放置在單元格的水平中心。 –