我有这个命令,当用户点击一个图像时,它会捕获:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [touches anyObject];
CGPoint touchLocation = [touch locationInView:self.view];
if(CGRectContainsPoint(card1.frame,touchLocation))
{
cardSelected = @"pagseguro";
[card1.layer setBorderColor: [[UIColor redColor] CGColor]];
[card1.layer setBorderWidth: 1.0];
[card2.layer setBorderColor: [[UIColor blackColor] CGColor]];
[card2.layer setBorderWidth: 1.0];
}
if(CGRectContainsPoint(card2.frame,touchLocation))
{
cardSelected = @"sumup";
[card1.layer setBorderColor: [[UIColor blackColor] CGColor]];
[card1.layer setBorderWidth: 1.0];
[card2.layer setBorderColor: [[UIColor redColor] CGColor]];
[card2.layer setBorderWidth: 1.0];
}
}在我输入scrollView之前,这段代码运行得很好,我按如下方式拉出了屏幕的滚动:
[self.view addSubview:scroll];
scroll.contentSize = scroll.frame.size;
scroll.frame = self.view.frame;现在触摸开始方法无法识别图像中的更多触摸,我如何修复它?
发布于 2014-07-23 05:54:51
尝试imageView.userInteractionEnabled = YES在imageView上的默认设置是no。
如果你在你的控制器中实现touchesBegan:withEvent:,它将不会工作,因为它会在UIView的子类中调用,所以你需要子类ScrollView,并且需要覆盖这个方法。
如果userInteractionEnabled无法工作,另一种选择是使用UITapGestureRecognizer,如果它适合您的需要。
https://stackoverflow.com/questions/24898366
复制相似问题