UIView 不接受触摸

发布于 2024-12-09 04:06:13 字数 844 浏览 0 评论 0原文

- (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぺ禁宫浮华殁 2024-12-16 04:06:13

将 UITapGestureRecognizer 添加到您的视图中

UITapGestureRecognizer *singleTapOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    singleTapOne.numberOfTouchesRequired = 1; singleTapOne.numberOfTapsRequired = 1; singleTapOne.delegate = self;
[self.view addGestureRecognizer:singleTapOne]; [singleTapOne release];
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
}

add UITapGestureRecognizer to your view

UITapGestureRecognizer *singleTapOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
    singleTapOne.numberOfTouchesRequired = 1; singleTapOne.numberOfTapsRequired = 1; singleTapOne.delegate = self;
[self.view addGestureRecognizer:singleTapOne]; [singleTapOne release];
- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer
{
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文