【问题标题】:Create a subview overlay for an Image View in a Table View on tap在点击时为表格视图中的图像视图创建子视图覆盖
【发布时间】:2015-07-23 01:00:22
【问题描述】:

我想创建一个在UITableView 上弹出的子视图,其中包含cell 上的UIImageView 全屏图像,右上角有一个退出按钮和UITextView底部的cell 另一个cellUITextView

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier(reuseIdentifier, forIndexPath: indexPath) as! TalesTableViewCell let tapGesture = UITapGestureRecognizer(target: self, action: "imageTapped:")

    cell.tableImage.addGestureRecognizer(tapGesture)

    cell.tableImage.userInteractionEnabled = true

    return cell
}

func imageTapped(gesture: UIGestureRecognizer) {

    //Code here I think

}

有什么想法吗?谢谢!

【问题讨论】:

    标签: ios xcode swift parse-platform


    【解决方案1】:

    使用以下代码..

    func imageTapped(gesture: UIGestureRecognizer) {
    
        var overlay : UIView = UIView(frame: CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height))
    
        var imageView : UIImageView = UIImageView(image: (gesture.view as! UIImageView).image) // This includes your image in table view cell
    
        imageView.frame = CGRectMake(0, 0, 0, 0) // set up according to your requirements
    
        var doneBtn : UIButton = UIButton(frame: CGRectMake(0, 0, 0, 0)) // set up according to your requirements
        doneBtn.addTarget(self, action: "pressed:", forControlEvents: .TouchUpInside)
    
        overlay.addSubview(imageView)
        overlay.addSubview(doneBtn)
    
        self.view.addSubview(overlay)
    }
    
    func pressed(sender: UIButton!) {
    
        sender.superview?.removeFromSuperview()
    }
    

    【讨论】:

      猜你喜欢
      • 2012-08-30
      • 2019-03-12
      • 1970-01-01
      • 1970-01-01
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多