UIView 不接受触摸
- (void)viewDidLoad {
checkingOption = [[UIView alloc] initWithFrame:CGRectMake(45, 250, 17, 15)];
checkingOption.backgroundColor = [UIColor grayColor];
checkingOption.layer.cornerRadius = 5;
checkingOption.layer.masksToBounds = YES;
checkingOption.opaque = NO;
[self.view addSubview:checkingOption];
[checkingOption setUserInteractionEnabled:YES];
}
这是我在主视图上的新内容。现在我想测试用户是否触及该视图...
-(void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event{
[self.usernameField resignFirstResponder];
[self.passwordField resignFirstResponder];
UITouch *touch =[touches anyObject];
CGPoint startPoint =[touch locationInView:checkingOption];
if(CGRectContainsPoint(checkingOption.frame,startPoint)){
NSLog(@"touch inside the checking view");
}
请帮助我..我没有发现问题。
提前致谢。
- (void)viewDidLoad {
checkingOption = [[UIView alloc] initWithFrame:CGRectMake(45, 250, 17, 15)];
checkingOption.backgroundColor = [UIColor grayColor];
checkingOption.layer.cornerRadius = 5;
checkingOption.layer.masksToBounds = YES;
checkingOption.opaque = NO;
[self.view addSubview:checkingOption];
[checkingOption setUserInteractionEnabled:YES];
}
That is my new on main view.now i want to test that is user touching on that or not...
-(void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event{
[self.usernameField resignFirstResponder];
[self.passwordField resignFirstResponder];
UITouch *touch =[touches anyObject];
CGPoint startPoint =[touch locationInView:checkingOption];
if(CGRectContainsPoint(checkingOption.frame,startPoint)){
NSLog(@"touch inside the checking view");
}
Please help me..i am not finding the problem.
Thanks in Advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 UITapGestureRecognizer 添加到您的视图中
add UITapGestureRecognizer to your view