UIImage不会识别轻拍手势Swift

时间:2016-07-14 21:02:12

标签: ios swift uiimage uitapgesturerecognizer

我正在尝试为侧面滚动视图中的某些UII图像添加一个轻触手势识别器,但是图像变平无法识别水龙头,我无法看到我出错的地方。我已经尝试过“scrollView.bringSubViewToFront(imgView)”,因为我认为它们可能会被埋没在其他视图的层中,但这也没有成功。 “contentView”是有问题的UIImageView,其中我的scrollView只是其中的一个集合。非常感谢,谢谢。

//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)
                }
            }

        }
    }
}

1 个答案:

答案 0 :(得分:4)

您是否已将UIImage属性userInteractionEnabled设置为true