如何使UIImageView显示全屏(Swift)

时间:2015-07-31 00:13:10

标签: swift uitableview uiimageview

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



}

2 个答案:

答案 0 :(得分: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 :(得分: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