gpt4 book ai didi

iphone - UITableView onTouch 隐藏键盘

转载 作者:行者123 更新时间:2023-12-03 20:43:14 26 4
gpt4 key购买 nike

我有一个 UITableView,其中放置了一个 UIButton (作为单元格的 subview )。同样在表格下方,我有一个 UITextField。触摸文本字段时,键盘会像平常一样出现。我想要的是在触摸 table 时关闭键盘。

我考虑的一个选项是为 UITableView 设置 UITapGestureRecognizer。但我放弃了这个想法,因为我在 tableCell 上有一个按钮,然后它变得没有响应。

此外,我不希望键盘上有“完成”或“返回”按钮。我的意思是,我不希望键盘从键盘上消失,而是在触摸 table 时注意它所具有的按钮。

最佳答案

也许你可以尝试一下。

//NSnotification when keyboard is shown
- (void)keyboardWasShown:(NSNotification *)notification
{
// Get the size of the keyboard.
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPhone){

if(UIInterfaceOrientationPortrait==orientation || UIInterfaceOrientationPortraitUpsideDown==orientation){
keyboardSize=CGSizeMake(320.000000, 216.000000);
}
else if(UIInterfaceOrientationLandscapeLeft==orientation || UIInterfaceOrientationLandscapeRight==orientation)
{
keyboardSize=CGSizeMake(162.000000, 480.000000);
}
}
else if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad){
if(UIInterfaceOrientationPortrait==orientation || UIInterfaceOrientationPortraitUpsideDown==orientation)
keyboardSize=CGSizeMake(768.000000, 264.000000);

else if(UIInterfaceOrientationLandscapeLeft==orientation || UIInterfaceOrientationLandscapeRight==orientation)
{
keyboardSize=CGSizeMake(352.000000,1024.000000);

}
}

// Adjust the bottom content inset of your scroll view by the keyboard height.
UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, keyboardSize.height, 0.0);
scrvwLogig.contentInset = contentInsets;
scrvwLogig.scrollIndicatorInsets = contentInsets;

// Scroll the target text field into view.
CGRect aRect = self.view.frame;
aRect.size.height -= keyboardSize.height;
if (!CGRectContainsPoint(aRect, txtpassword.frame.origin) ) {

CGPoint scrollPoint=CGPointZero;
//check flag for iPhone orientation
if(flgLandScape)
scrollPoint = CGPointMake(0.0, txtpassword.frame.origin.y-70);
//check flag for iPhone/iPad orientation
else if(flgPort || flgPortiPad)
scrollPoint = CGPointMake(0.0, txtpassword.frame.origin.y - (keyboardSize.height-50));
//check flag for ipad orientation
else if(flgLandScapeiPad)
scrollPoint = CGPointMake(0.0, txtpassword.frame.origin.y-130);

[scrvwLogig setContentOffset:scrollPoint animated:YES];
}
}


//when keyboard is hide

- (void) keyboardWillHide:(NSNotification *)notification {

UIEdgeInsets contentInsets = UIEdgeInsetsZero;
scrvwLogig.contentInset = contentInsets;
scrvwLogig.scrollIndicatorInsets = contentInsets;
}

关于iphone - UITableView onTouch 隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9700395/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com