我在 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) {
}
最佳答案
您必须创建一个自定义TableviewCell,其中有一个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
}
关于swift - 如何使 UIImageView 全屏显示(Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31736131/