问题描述
我知道这是一个非常常见的问题,但是每个网站上的所有答案都不起作用!如果你还是不明白我的意思,那么也许这行代码可以帮助你理解.
I know that this is a very commonly asked question, but all of the answers on every website don't work! If you still don't know what I mean, then maybe this line of code will help you understand.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
CGPoint location = [touch locationInView:self.view];
if (touch.view == nextbutton)
[self performSelector:@selector(next)];
if (touch.view == prevbutton)
[self performSelector:@selector(previous)];
if (touch.view == moreoptionsbutton)
[self performSelector:@selector(moresettings)];
}
当你触摸 nextbutton、prevbutton 和 more optionsbutton
时,它不会做任何事情,顺便说一下,它们是 UIImageViews
.我也尝试过使用 isEqual:
而不是 ==
,但这也没有成功.有什么建议吗?
It doesn't do anything when you touch nextbutton, prevbutton, and more optionsbutton
, which are UIImageViews
by the way. I have also tried using isEqual:
instead of ==
, but that hasn't worked out either. Any suggestions?
推荐答案
你必须为你所有的 UIImageViews 设置 userinteractionEnabled = YES 否则他们将不会收到触摸事件.同时换行:
You have to set userinteractionEnabled = YES for all your UIImageViews otherwise they will not receive touch events. Also change the line:
UITouch *touch = [[event allTouches] anyObject];
到
UITouch *touch = [touches anyObject];
这篇关于你如何知道在 touchesBegan 中被触摸的对象是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!