检测Xcode中某个对象的触摸

时间:2012-01-16 13:08:46

标签: ios xcode cocoa-touch touch

这个伪代码的Xcode代码是什么?

if ([Any UIPickerView in my ViewController isTouched]) {
    [AnyUIView setHidden:NO];
}

if ([Any UIPickerView in my ViewController is__NOT__Touched__Anymore__]) {
    [AnyUIView setHidden:YES];
}

使用-(void)touchesBegan方法尝试它,它会检测到触摸,但我无法将其设置为特定于对象。感谢

P.S。我想在触摸UIPickerView时在显示屏上显示提示。

1 个答案:

答案 0 :(得分:1)

这只是我的头脑......但你应该能够理解......

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    UITouch *touch = [touches anyObject];
    if ([touch.view isKindOfClass: UIPickerView.class]) {
         //your touch was in a uipickerview ... do whatever you have to do
    }
}

..并对touchesEnded:withEvent:

执行相同的操作