0

我有触摸方法,但它仅在我单击视图的某些区域时才有效,而不是无处不在。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];// this will do the trick
}

我该如何解决这个问题?

谢谢

4

2 回答 2

0

好的,尝试使用以下代码并检查:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITouch *touch = [touches anyObject];
    [touch locationInView:self.view];
    [self.view endEditing:YES];
}
于 2013-03-05T03:11:50.500 回答
0

尝试这个

- (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];
}
于 2013-03-05T04:23:22.027 回答