gpt4 book ai didi

ios - UIImage 不会识别点击手势 Swift

转载 作者:行者123 更新时间:2023-11-28 10:18:26 24 4
gpt4 key购买 nike

我正在尝试向侧 ScrollView 中的某些 UIImages 添加轻击手势识别器,但平整的图像无法识别轻击,而且我看不出哪里出错了。我尝试过“scrollView.bringSubViewToFront(imgView)”,因为我认为它们可能会被其他 View 层所掩盖,但这也没有起到作用。 “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)
}
}

}
}
}

最佳答案

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

关于ios - UIImage 不会识别点击手势 Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38384187/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com