我有一个简单UIImageView
的动画,我需要检测它的点击。我添加了一个UIButton
这是 this 的子视图UIImageView
。但是,点击它不起作用。添加到视图时,我已经对其UIButton
本身进行了测试,并且它可以工作,所以不是导致问题的按钮。
这是代码:
self.red = [[UIImageView alloc] initWithFrame:CGRectMake(50, 300, 85, 100)];
self.red.image = [UIImage imageNamed:@"red.png"];
[self.red setUserInteractionEnabled: YES];
[self.view addSubview: self.red];
[self.view bringSubviewToFront:self.red];
UIButton *redButton = [UIButton buttonWithType: UIButtonTypeCustom];
redButton.frame = CGRectMake(self.red.frame.origin.x, self.red.frame.origin.y, self.red.frame.size.width, self.red.frame.size.height);
[redButton addTarget: self action:@selector(correctButtonClick) forControlEvents: UIControlEventAllTouchEvents];
[redButton setUserInteractionEnabled:YES];
[self.red addSubview: redButton];
[self.red bringSubviewToFront:redButton];
我在这里做错了什么?