Ios UIImage无法识别轻触手势
我正在尝试将点击手势识别器添加到侧滚动视图中的一些UIImage中,但是这些图像无法识别点击,我看不出哪里出了问题。我尝试过“scrollView.bringSubViewToFront(imgView)”,因为我认为它们可能被其他视图的层所掩埋,但这也没有起作用。“contentView”是所讨论的UIImageView,其中我的scrollView只是其中的一个集合。如果您有任何帮助,我们将不胜感激,谢谢Ios UIImage无法识别轻触手势,ios,swift,uiimage,uitapgesturerecognizer,Ios,Swift,Uiimage,Uitapgesturerecognizer,我正在尝试将点击手势识别器添加到侧滚动视图中的一些UIImage中,但是这些图像无法识别点击,我看不出哪里出了问题。我尝试过“scrollView.bringSubViewToFront(imgView)”,因为我认为它们可能被其他视图的层所掩埋,但这也没有起作用。“contentView”是所讨论的UIImageView,其中我的scrollView只是其中的一个集合。如果您有任何帮助,我们将不胜感激,谢谢 //function to create contentScrollView for
//function to create contentScrollView for MiniMatches
func setupMiniContentScroll(contentScroll: UIScrollView) {
let scalar:Double = 4/19
let contentViewDimension = contentScroll.frame.width * CGFloat(scalar)
let contentScrollWidth = CGFloat(LocalUser.matches.count) * (contentViewDimension + CGFloat(12)) - CGFloat(12)
let matchManager = MatchesManager()
for index in 0..<LocalUser.matches.count {
let match = LocalUser.matches[index]
matchManager.retrieveMatchThumbnail(match) { img, error in
if let img = img {
//create the mini matches views
let xOrigin = index == 0 ? 12 : CGFloat(index) * contentViewDimension + (CGFloat(12) * CGFloat(index) + CGFloat(12))
let contentFrame = CGRectMake(xOrigin, 10, contentViewDimension, contentViewDimension)
let contentView = self.makeMiniContentView(contentFrame, image: img, matchedPrice: match.matchedPrice)
let tap = UITapGestureRecognizer(target: self, action: #selector(BrowseViewController.toggleItemInfo(_:)))
contentView.addGestureRecognizer(tap)
self.miniMatchContainer.append(contentView)
//update the contentScrollView
dispatch_async(dispatch_get_main_queue()) {
let contentLabelFrame = CGRect(x: xOrigin, y: contentFrame.height + 15, width: contentFrame.width, height: 20)
let contentLabel = self.makeMiniContentLabel(contentLabelFrame, itemName: match.itemName)
let priceLabel = self.makeMiniPriceLabel(contentFrame, matchedPrice: match.matchedPrice)
contentScroll.addSubview(contentView)
contentScroll.addSubview(contentLabel)
contentScroll.addSubview(priceLabel)
contentScroll.contentSize = CGSizeMake(contentScrollWidth + CGFloat(16), contentScroll.frame.height)
}
}
}
}
}
//为最小匹配创建contentScrollView的函数
func setupMiniContentScroll(contentScroll:UIScrollView){
设标量:Double=4/19
让contentViewDimension=contentScroll.frame.width*CGFloat(标量)
让contentScrollWidth=CGFloat(LocalUser.matches.count)*(contentViewDimension+CGFloat(12))-CGFloat(12)
让matchManager=MatchesManager()
对于0..中的索引,您是否将UIImage
属性userInteractionEnabled
设置为true
?您是否将UIImage
属性userInteractionEnabled
设置为true
?尝试使用点击手势制作一个单独的函数,例如func-imagetappet(){let tap=uitapurerecognizer(目标:self,action:#选择器(BrowseViewController.toggleItemInfo(:))contentView.addgestureRecognitizer(tap)self.miniMatchContainer.append(contentView)}在if语句中调用函数imagestapped(),尝试使用tap手势制作一个单独的函数,例如func imagestapped(){let tap=uitappesturerecognizer(目标:self,操作:#选择器(BrowseViewController.toggleItemInfo(:))contentView.addgesturecognizer(tap)self.miniMatchContainer.append(contentView)}if语句中的函数调用函数imageTapped()