简体   繁体   English

如何使 UITableView 上方的视图动态化?

[英]How to make the view above a UITableView dynamic?

I have a view on top of a tableviewController.我在 tableviewController 上有一个视图。 However, I want to make the view dynamic.但是,我想让视图动态化。
Current constraints aren't working.当前约束不起作用。

不工作,这个例子中的视图应该更短

当前限制,在所有四个方面设置;我试过删除底部约束,但文本视图刚刚离开屏幕

What other approaches can I take to this?我可以采取哪些其他方法来解决这个问题? My current constraints are on all four sides, I've tried removing the bottom constraint, but this has the view go off the screen instead of pushing the view controller down我当前的约束在所有四个方面,我已经尝试删除底部约束,但这使视图离开屏幕而不是向下推视图控制器

The other alternative I thought of is to have the text view and table view on the same "level" (instead of imbedded) but then the table view is just scrolling instead of moving the entire screen.我想到的另一种选择是将文本视图和表格视图放在同一“级别”(而不是嵌入)上,但表格视图只是滚动而不是移动整个屏幕。

For Dynamic Text view对于动态文本视图

In Storyboard / Interface Builder simply disable scrolling in the Attribute inspector.在 Storyboard / Interface Builder 中,只需在属性检查器中禁用滚动。

In code textField.isScrollEnabled = false should do the trick.在代码中textField.isScrollEnabled = false应该可以解决问题。 But if in case it doesn't resolve your problem you can set bottom constraint like below但是,如果它不能解决您的问题,您可以设置如下所示的底部约束

Step1: get a IB outlet Step1:获取IB插座

@IBOutlet weak var textViewHeight: NSLayoutConstraint!

Step2: use the delegation method below. Step2:使用下面的委托方式。

extension NewPostViewController: UITextViewDelegate {
     func textViewDidChange(_ textView: UITextView) {
          textViewHeight.constant = self.textView.contentSize.height + 10
     }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM