我在UITableViewCell中有一个UIImageView。轻按图像时,我希望图像以全屏显示。我需要在代码中添加什么?
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let tapRecognizer = UITapGestureRecognizer(target: self, action: "makeLarger")
cell.itemImage.addGestureRecognizer(tapRecognizer)
return cell
}
func makeLarger(gesture: UIGestureRecognizer) {
}
您必须创建一个customTableviewCell,其中有一个ImageView IBOutlet,然后在viewDidLoad()中追加数据数组。
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! CustomTableViewCell
var images = self.data[indexPath.row]
cell.imageview.image = UIImage(named: images)
cell.imageview.userInteractionEnabled = true
cell.imageview.multipleTouchEnabled = true
var tapgesture = UITapGestureRecognizer(target: self, action: Selector("tap"))
tapgesture.numberOfTapsRequired = 1
cell.addGestureRecognizer(tapgesture)
return cell
}
func tap(){
print("tap")
// then you should pass the single image to the DestinationViewController
}