Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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 AutoLayout UITableView表格/屏幕的单元格高度倍数_Ios_Swift_Uitableview_Autolayout_Uikit - Fatal编程技术网

Ios AutoLayout UITableView表格/屏幕的单元格高度倍数

Ios AutoLayout UITableView表格/屏幕的单元格高度倍数,ios,swift,uitableview,autolayout,uikit,Ios,Swift,Uitableview,Autolayout,Uikit,我有一个tableViewCell,其中包含一个imageSlider,应该是屏幕高度的40% 这在自动布局中是可能的吗?将单元格添加到tableView后,已经计算了该单元格的高度,因此将忽略添加的任何单元格高度约束 我可以实现heightForRow并返回正确的值,但我想知道是否仅使用AutoLayout就可以实现这一点 cell.imageSlider.heightAnchor.constraint(equalTo: tableView.heightAnchor, multiplier:

我有一个tableViewCell,其中包含一个imageSlider,应该是屏幕高度的40%

这在自动布局中是可能的吗?将单元格添加到tableView后,已经计算了该单元格的高度,因此将忽略添加的任何单元格高度约束

我可以实现heightForRow并返回正确的值,但我想知道是否仅使用AutoLayout就可以实现这一点

cell.imageSlider.heightAnchor.constraint(equalTo: tableView.heightAnchor, multiplier: 0.4)

向图像滑块添加高度约束,并在单元格中声明相应的iboutlet。将其常量值设置为view.bounds.size.height/60.0。让我知道它是否有效。

向图像滑块添加高度约束,并在单元格中声明相应的iboutlet。将其常量值设置为view.bounds.size.height*0.4。从superView(在您的示例中为TableViewCell)设置imageSlider的顶部和底部约束。让我知道它是否有效。 另外,添加以下代码

- (void)viewWillLayoutSubviews{
    [self.imageSlider layoutIfNeeded];
    //OR 
    [cell layoutIfNeeded];
}

layoutIfNeeded将自动更新约束。

这不是我想要的,因为每次边界更改时,我都必须手动更新常量……因为滑块位于单元格内,所以它不会根据自动绑定的视图调整自身大小。您可以将该代码放置在cell类中的cellForRowAtIndexPath或awakfromNib方法中。您的代码(view.bounds.size.height/60)不起作用,因为它使幻灯片的大小为视图大小的60。bounds.height*0.4可以工作,但不会在旋转更改时自动更新。因此,tableView(tableView:UITableView,heightForRowAt indexPath:indexPath)->CGFloat似乎是更好的选择。重写func ViewWillTransitionSize(size:CGSize,with TransitionCoordinator:UIViewControllerTransitionCoordinator)在这个方法中调用tableView.reloadDatayes,这是我的错误。它应该是view.bounds.size.height*0.4这与@Deepak Kumar的建议大致相同(见下文)。高度将不适应不断变化的view.bounds。