我UITableView在iOS 8下运行,并且我在故事板中使用来自约束的自动单元格高度.
我的一个单元格包含一个UITextView,我需要它根据用户输入收缩和扩展 - 点击缩小/扩展文本.
我这样做是通过向文本视图添加运行时约束并更改约束上的常量以响应用户事件:
-(void)collapse:(BOOL)collapse; {
_collapsed = collapse;
if(collapse)
[_collapsedtextHeightConstraint setConstant: kCollapsedHeight]; // 70.0
else
[_collapsedtextHeightConstraint setConstant: [self idealCellHeightToShowFullText]];
[self setNeedsUpdateConstraints];
}
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我将其包装在tableView更新中并致电[tableView setNeedsUpdateConstraints]:
[tableView beginUpdates];
[_briefCell collapse:!_showFullBriefText];
[tableView setNeedsUpdateConstraints];
// I have also tried
// [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
// with exactly the same results.
[tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
当我这样做时,我的单元格确实扩展(并在进行动画时动画)但是我得到一个约束警告:
2014-07-31 13:29:51.792 OneFlatEarth[5505:730175] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one …Run Code Online (Sandbox Code Playgroud) 我需要裁剪一个UIImage,用设备相机拍摄,以便它适合另一个UIImage,它代表一个frame(带有圆形边框等).检查下图:
使用Aspect Fill
使用Aspect Fit
所以,我需要的是删除超出帧边界的图像多余.我尝试使用UIBezierPath,CGImageRef而我Google其他方法,但是我没有找到一个解决方案.
到目前为止,我一直只是在单元格中使用自动调整大小的文本标签.我通常将约束放在所有边(内容视图或邻居)上,并将以下行添加到我的viewDidLoad():
// 190.0 is the actual height of my custom cell (see next image) in the storyboard containing a label and a randomly sized UIImageView
tableView.estimatedRowHeight = 190.0
tableView.rowHeight = UITableViewAutomaticDimension
Run Code Online (Sandbox Code Playgroud)
现在,当试图包含图像时,我遇到了几个问题.在一些研究中,我发现了几种用Objective-C编写的方法,但是我不确定哪些方法真正解决了我的核心问题,我仍在努力解决复杂的Objective-C代码问题.所以要恢复:我的最终目标是获得一个具有正确大小(正确的高度)单元格的表格,每个单元格包含一个符合屏幕宽度的标题和图像.那些图像可以具有不同的纵横比和不同的尺寸.为了简化一些挑战,我准备了一个新的,更简单的项目:
UITableViewController和一个CustomCell类具有两个IBOutlets title: String和postedImage: UIImage(随机的UIImage在故事板的尺寸)来配置所述细胞.我定义了边缘和彼此的约束.

在我的一个更复杂的项目中,我想要不同的图像自动适应屏幕的宽度,无论它们是纵向还是横向 - 如果它们的宽度小于屏幕的宽度,它们应该按比例放大.与上面的项目一样,每个单元格高度应符合故事板中约束所定义的各个内容.无论如何,它从上面讨论的问题开始:我怎样才能让这两个单元格具有相同的正确高度,拥抱故事板中定义的内容?
万分感谢您的帮助!
我有一个设置的tableview:
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 50;
Run Code Online (Sandbox Code Playgroud)
它在5/5s,6/6s,7中工作正常,但它不能在6s +/7 +中工作,图像是伸展的.
ios ×3
uitableview ×3
autolayout ×2
cocoa-touch ×1
ios8 ×1
iphone ×1
objective-c ×1
swift ×1
uiimage ×1