我知道这是一个非常常见的问题,但每个网站上的所有答案都不起作用!如果你还是不明白我的意思,那么也许这行代码会帮助你理解。
- (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, and more optionsbutton
, 哪个是UIImageViews
顺便一提。我也尝试过使用isEqual:
代替==
,但这也没有成功。有什么建议么?
您必须为所有 UIImageView 设置 userinteractionEnabled = YES,否则它们将不会收到触摸事件。还要更改行:
UITouch *touch = [[event allTouches] anyObject];
to
UITouch *touch = [touches anyObject];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)