如何使UIImageView全屏显示(Swift)

问题描述 投票:2回答:2

我在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) {



}
swift uitableview uiimageview
2个回答
1
投票

您必须创建一个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 
}

1
投票

此代码使您的imageView全屏显示:

let screenSize: CGRect = UIScreen.mainScreen().bounds
let screenWidth = screenSize.width
let screenHeight = screenSize.height
imageView.frame = CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight)

看起来像这样(点击按钮后,图像变为全屏显示)the gif

© www.soinside.com 2019 - 2024. All rights reserved.