Ios UIScrollView检测抽头
我有一个UIScrollView,我需要能够在其中滚动。同时,我需要检测scrollview上的点击。我怎样才能做到这一点 我已经尝试在没有任何运气的情况下向视图中添加TapGestureRecognitor。还尝试了几种使用UIScrollViewDelegate方法的方法 在UIScrollView中有MPMoviePlayerController视图 我使用了下面的代码添加重新引导器Ios UIScrollView检测抽头,ios,uiview,uiscrollview,uitapgesturerecognizer,Ios,Uiview,Uiscrollview,Uitapgesturerecognizer,我有一个UIScrollView,我需要能够在其中滚动。同时,我需要检测scrollview上的点击。我怎样才能做到这一点 我已经尝试在没有任何运气的情况下向视图中添加TapGestureRecognitor。还尝试了几种使用UIScrollViewDelegate方法的方法 在UIScrollView中有MPMoviePlayerController视图 我使用了下面的代码添加重新引导器 UITapGestureRecognizer *singleTap = [[[UITapGestureRe
UITapGestureRecognizer *singleTap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)] autorelease];
singleTap.enabled = YES;
singleTap.cancelsTouchesInView = NO;
[scrollView addGestureRecognizer:singleTap];
谢谢。尝试将一个视图放在滚动视图中,并向其中添加手势识别器和其他视图。解决方案:将MPMoviePlayerController视图添加到UIScrollView时,需要禁用MPMoviePlayerController视图上的用户交互,以便UIScrollView能够捕获手势识别器。只有当您不想使用MPMoviePlayerController默认菜单等进行交互时,此解决方案才有效。您可以在UIScrollView中捕获任何类型的手势。确保还处理一些默认属性,如将cancelsTouchesInView属性设置为false,默认情况下为true。同时为子视图提供一些标记号,以便在选择器中进行区分也使他们的用户交互成为现实 例如,我在我的滚动视图中添加了一个图像视图,我启用了它的用户交互,我还更新了它的内容大小
{
//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)
{
//向滚动视图添加图像
对于0..<4中的i{
让image=UIImage(命名为:“img\(i).png”)
让imageView=UIImageView(图像:图像)
imageView.center=CGPoint(x:CGFloat(i)*60+60/2,y:60/2)
imageView.tag=i
imageView.isUserInteractionEnabled=true
添加子视图(图像视图)
让tap=UITapGestureRecognitor(目标:自我,操作:#选择器(didTapImage(:))
imageView.AddGestureRecognitor(点击)
}
contentSize=CGSize(宽:10*60,高:60+2*10)
}您的回答不是正确的解决方案,但是,它让我想到了这一点。当我在scrollview中添加mp视图时,我必须禁用scrollview的mpmovieplayercontroller上的用户交互来处理手势。然后将您的解决方案作为答案,并将其作为正确答案接受。