Ios 触摸或滚动后,自定义表格视图单元格中的图像视图意外调整大小
我在一个表视图中有一个自定义的表单元格,它包含一个图像视图和文本字段的水平堆栈视图。。。图像视图模式为ScaleSpectFit 最初加载视图时,视图按其应有的方式排列,但当触摸单元格或滚动表格视图时,图像视图会意外调整大小 这里是截图和我的代码Ios 触摸或滚动后,自定义表格视图单元格中的图像视图意外调整大小,ios,swift,uiimageview,Ios,Swift,Uiimageview,我在一个表视图中有一个自定义的表单元格,它包含一个图像视图和文本字段的水平堆栈视图。。。图像视图模式为ScaleSpectFit 最初加载视图时,视图按其应有的方式排列,但当触摸单元格或滚动表格视图时,图像视图会意外调整大小 这里是截图和我的代码 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let
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的约束。它应该是
中心垂直对齐
,前导
,固定宽度
和固定高度
,尝试以下步骤,可能会对您有所帮助
clipSubviews=YES
。在故事板中或cell.imageViewPic.clipsToBounds=YES代码>
尝试以下步骤,它可能会对您有所帮助
clipSubviews=YES
。在故事板中或cell.imageViewPic.clipsToBounds=YES代码>
如果使用自动布局,imageview已经有哪些约束?同样在这种情况下,REVEL或Xcode视图调试功能也会很方便。你能发布你的getImage函数代码吗?如果你使用自动布局,imageview已经有哪些约束?同样在这种情况下,REVEL或Xcode视图调试功能也会很方便。你能发布你的getImage函数代码吗?@Hadi关于约束怎么办?@Hadi关于约束怎么办?