2016-07-14 63 views
0

我想添加點擊手勢識別器到一些側向滾動視圖中的UIImages,但圖像扁平不會識別點擊,我看不到點擊錯誤。我試過「scrollView.bringSubViewToFront(imgView)」,因爲我想他們可能會被埋在其他視圖的圖層中,但是這也沒有辦法。 「contentView」是有問題的UIImageView,其中我的scrollView只是這些的集合。任何幫助在這裏將不勝感激,謝謝。UIImage不會識別點按手勢Swift

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

     } 
    } 
} 
+0

嘗試做一個單獨的功能方面與它的點觸手勢,例如FUNC imageTapped(){ 讓 自來水= UITapGestureRecognizer(目標:自我,動作:#selector(BrowseViewController.toggleItemInfo(_ :))) 內容查看。 addGestureRecognizer(tap) self.miniMatchContainer.append(contentView) } 在if語句中調用函數imageTapped() – Konsy

回答

2

你有沒有設置UIImage屬性userInteractionEnabledtrue