Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 触摸或滚动后,自定义表格视图单元格中的图像视图意外调整大小_Ios_Swift_Uiimageview - Fatal编程技术网

Ios 触摸或滚动后,自定义表格视图单元格中的图像视图意外调整大小

Ios 触摸或滚动后,自定义表格视图单元格中的图像视图意外调整大小,ios,swift,uiimageview,Ios,Swift,Uiimageview,我在一个表视图中有一个自定义的表单元格,它包含一个图像视图和文本字段的水平堆栈视图。。。图像视图模式为ScaleSpectFit 最初加载视图时,视图按其应有的方式排列,但当触摸单元格或滚动表格视图时,图像视图会意外调整大小 这里是截图和我的代码 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let

我在一个表视图中有一个自定义的表单元格,它包含一个图像视图和文本字段的水平堆栈视图。。。图像视图模式为ScaleSpectFit

最初加载视图时,视图按其应有的方式排列,但当触摸单元格或滚动表格视图时,图像视图会意外调整大小

这里是截图和我的代码

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("ImagesTableViewCell", forIndexPath: indexPath) as! ImagesTableViewCell

    // Configure the cell...
    let pic = self.patient!.images[indexPath.row]
    cell.imageViewPic.clipsToBounds = true
    cell.imageViewPic.contentMode = .ScaleAspectFit
    cell.imageViewPic.image = getImage(pic.imagePath)
    cell.labelPic.text = pic.caption
    cell.imageViewPic.tag = indexPath.row
    cell.labelPic.tag = indexPath.row

    return cell
}
我尝试了所有的内容模式,但没有任何好处

Edit2:以下是请求的getImage()函数代码

func getImage(filename: String) -> UIImage {
    let path =         getDocumentsDirectory().stringByAppendingPathComponent(filename)
    let image = UIImage(contentsOfFile: path)
    return image!
}

UIImageView
clipstobunds
属性设置为
true

设置
cell.imageViewPic.clipsToBounds=true


还要检查imageview的约束。它应该是
中心垂直对齐
前导
固定宽度
固定高度

UIImageView
clipsToBounds
属性设置为

设置
cell.imageViewPic.clipsToBounds=true


还要检查imageview的约束。它应该是
中心垂直对齐
前导
固定宽度
固定高度
,尝试以下步骤,可能会对您有所帮助

  • 渲染具有固定宽度和高度的ImageView
  • 使
    clipSubviews=YES
    。在故事板中或
    cell.imageViewPic.clipsToBounds=YES

  • 尝试以下步骤,它可能会对您有所帮助

  • 渲染具有固定宽度和高度的ImageView
  • 使
    clipSubviews=YES
    。在故事板中或
    cell.imageViewPic.clipsToBounds=YES

  • 如果使用自动布局,imageview已经有哪些约束?同样在这种情况下,REVEL或Xcode视图调试功能也会很方便。你能发布你的getImage函数代码吗?如果你使用自动布局,imageview已经有哪些约束?同样在这种情况下,REVEL或Xcode视图调试功能也会很方便。你能发布你的getImage函数代码吗?@Hadi关于约束怎么办?@Hadi关于约束怎么办?