检测对 Xcode 中某个对象的触摸
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8880462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Detect a touch on a certain object in Xcode
提问by DAS
What's the Xcode code for this pseudocode?
这个伪代码的 Xcode 代码是什么?
if ([Any UIPickerView in my ViewController isTouched]) {
[AnyUIView setHidden:NO];
}
if ([Any UIPickerView in my ViewController is__NOT__Touched__Anymore__]) {
[AnyUIView setHidden:YES];
}
Tried it with the -(void)touchesBegan
method, it detects the touches but I was not able to make it object-specific. Thanks
使用该-(void)touchesBegan
方法进行了尝试,它会检测到触摸,但我无法使其特定于对象。谢谢
P.S. I want to display a hint on the display while the UIPickerView
is touched.
PS我想在UIPickerView
触摸时在显示屏上显示提示。
回答by bandejapaisa
This is just from the top of my head...... but you should be able to get the idea...
这只是从我的头顶......但你应该能够得到这个想法......
- (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
}
}
..and do the same with touchesEnded:withEvent:
..并做同样的事情 touchesEnded:withEvent: