【问题标题】:How to make a UIImageView display fullscreen (Swift)如何使 UIImageView 全屏显示(Swift)
【发布时间】:2015-10-22 12:57:56
【问题描述】:

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



}

【问题讨论】:

  • 你现在没有任何代码你传递给我朋友的数据在哪里
  • 我在 cellForRowAtIndexPath 中创建了一个点击手势,然后创建了动作函数 makeLarger。你能告诉我我哪里错了吗?欣赏它。

标签: swift uitableview uiimageview


【解决方案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 
}

【讨论】:

  • 我认为这个有问题,因为使用这种方式,如果您在单元格中点击一个,您将无法选择要显示的图像
【解决方案2】:

这段代码让你的 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)

看起来像这样(点击按钮后图像变成全屏)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-10
    • 2014-06-07
    • 1970-01-01
    • 2021-12-20
    • 2011-02-26
    • 2014-11-29
    相关资源
    最近更新 更多