我经历了所有的解决方案,但没有一个有效。我正在开发适用于 iOS 6 的应用程序 ipad。当用户触摸外部(在滚动视图上)时,我希望键盘消失......
问问题
3718 次
8 回答
6
在 viewDidLoad 中给出以下代码
-(void) ViewDidLoad
{
UITapGestureRecognizer *tapScroll = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapped)];
tapScroll.cancelsTouchesInView = NO;
[scrollview addGestureRecognizer:tapScroll];
}
并定义函数如下
- (void) tapped
{
[self.view endEditing:YES];
}
于 2013-05-17T10:08:23.237 回答
1
将滚动视图委托设置为自我
self.scrollView.delegate=self;
然后
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if (sTitle.isFirstResponder) {
[sTitle resignFirstResponder];
}
}
于 2013-05-17T10:16:12.840 回答
1
尝试使用这个。我希望它会有所帮助。
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyBoard:)];
gestureRecognizer.delegate = self;
[scrollView addGestureRecognizer:gestureRecognizer];
}
-(void) hideKeyBoard:(UIGestureRecognizer *) sender
{
[self.view endEditing:YES];
}
于 2013-05-17T10:06:20.590 回答
1
您可以使用此代码隐藏键盘:
-(void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideTheKeyBoard:)];
gestureRecognizer.delegate = self;
[scrollView addGestureRecognizer:gestureRecognizer];
}
-(void) hideTheKeyBoard:(UIGestureRecognizer *)sender
{
[self.view endEditing:YES];
}
于 2013-05-17T10:17:10.017 回答
0
UITapGestureRecognizer *tapScroll = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Click)];
ScrollClick.cancelsTouchesInView = NO;
[YOUR scrollview addGestureRecognizer:ScrollClick];
- (void)Click
{
[self.view endEditing:YES];
}
试试这个。我希望它对你有帮助。好好享受 !
于 2013-05-18T05:04:50.893 回答
0
add custom button on scrollview and
-(IBAction)btn:(id)sender
{
[txt resignfirstresponder];
}
enjoy it!!
于 2013-05-17T10:19:31.970 回答
0
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setDelegate:self];
[scrollview addGestureRecognizer:tapRecognizer];
-(void)tapped:(id)sender {
[textField resignFirstResponder];
// your code what you want
}
于 2013-05-17T10:08:25.783 回答
0
如果您正在使用,xib
那么只需将 a 连接tapRecognizer
到您的scrollview
然后创建tapRecognizer's
选择器事件[self.view endEditing:YES]
于 2013-05-17T10:12:08.477 回答