我有触摸方法,但它仅在我单击视图的某些区域时才有效,而不是无处不在。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];// this will do the trick
}
我该如何解决这个问题?
谢谢
我有触摸方法,但它仅在我单击视图的某些区域时才有效,而不是无处不在。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.view endEditing:YES];// this will do the trick
}
我该如何解决这个问题?
谢谢
好的,尝试使用以下代码并检查:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
[touch locationInView:self.view];
[self.view endEditing:YES];
}
尝试这个
- (void)viewDidLoad
{
[super viewDidLoad];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
[self.view addGestureRecognizer:singleTap];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
{
//Get touch point
CGPoint touchPoint=[gesture locationInView:self.view];
//Hide keyBoard
[self.view endEditing:YES];
}