【发布时间】:2018-06-11 11:51:06
【问题描述】:
我有一个 UIView,其中包含许多 UITextViews 调整大小以适应文本,最后一个文本视图通过 Autolayout 连接到父 UIView 的基础。然后 UIView 使用以下方法动态添加到 UIScrollView
for (UIView *subview in self.scrollViewContent.subviews) {
[subview removeFromSuperview];
}
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
NSLog(@"%f",self.txtViewEndOfFAQ.frame.size.height);
[self.viewFAQ setFrame:CGRectMake(0, 0, screenWidth, (self.txtViewEndOfFAQ.frame.origin.y + self.txtViewEndOfFAQ.frame.size.height))];
[self.scrollViewContent addSubview:self.viewFAQ];
[self.scrollViewContent setContentSize:CGSizeMake(self.viewFAQ.frame.size.width, self.viewFAQ.frame.size.height)];
[self addUnderline:self.imageViewTitle4];
[self showMenu:nil];
现在的问题是,当它加载时它没有给我正确的高度。对于较窄的设备,文本视图的高度会增加以适应文本,这似乎没有被考虑在内。
【问题讨论】:
-
为什么不简单地使用 UITableView。会容易很多
-
我同意@rv7284。使用带有自动行高计算的表格视图。它应该很简单,iOS 会自动为你管理这些事情。
-
你在哪里运行这段代码?是否在 viewDidLoad 中?
-
不,稍后按下 UIButton,我想我会尝试切换到 UITableView 看看会发生什么。
标签: ios objective-c