- (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");
}
请帮帮我..我找不到问题。
先谢谢。
答案 0 :(得分:0)
将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
{
}