我有一个UIScrollView,我需要在其中能够滚动。同时,我需要检测滚动视图上的点击。我怎样才能做到这一点呢?
我已经尝试将一个TapGestureRecognizer添加到视图中,但没有成功。我还尝试了几种使用UIScrollViewDelegate方法的方法。
在UIScrollView中有一个MPMoviePlayerController视图。
我使用下面的代码添加了reconigzer
UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)] autorelease];
singleTap.enabled = YES;
singleTap.cancelsTouchesInView = NO;
[scrollView addGestureRecognizer:singleTap];谢谢。
发布于 2012-03-07 21:52:30
解决方案:当向UIScrollView添加MpMoviePlayerController的视图时,需要禁用MpMoviePlayerController视图上的用户交互,以便UIScrollView能够捕获手势识别器。只有当你不想使用mpmovieplayercontrollers控制器、默认菜单等进行交互时,这个解决方案才能起作用。
发布于 2012-03-05 03:29:44
尝试将一个视图放在滚动视图中,并向其中添加手势识别器和其他视图。
发布于 2017-05-02 02:21:02
您可以在UIScrollView中捕获任何类型的手势。确保您还处理了一些默认属性,如将cancelsTouchesInView属性设置为false,它在默认情况下为真。也给你的子视图一些标签号,以便在选择器中进行区分。将其用户交互设置为true (&A)。
例如。我正在我的滚动视图中添加一个图像视图,我也在启用它的用户交互,我还在更新它的内容大小。
{
//adding images to the scroll view
for i in 0 ..< 4 {
let image = UIImage(named: "img\(i).png")
let imageView = UIImageView(image: image)
imageView.center = CGPoint(x: CGFloat(i) * 60 + 60/2, y: 60/2)
imageView.tag = i
imageView.isUserInteractionEnabled = true
addSubview(imageView)
let tap = UITapGestureRecognizer(target: self, action: #selector(didTapImage(_:)))
imageView.addGestureRecognizer(tap)
}
contentSize = CGSize(width: 10 * 60, height: 60 + 2*10) }
https://stackoverflow.com/questions/9558066
复制相似问题