嘿所以我正在为我的应用程序开发RSS博客阅读器组件,我遇到了正确调整堆栈视图大小的问题,该视图包含我解析的博客内容的textview和图像视图。尺寸问题来自于无法获得单个文本视图和图像视图的正确高度的事实。
请原谅我的iOS知识空白。我一直在教自己,所以有时这些问题只是让我在基本层面上抓住了。
我尝试过做一些其他的堆栈溢出问题,比如添加
self.view.setNeedsDisplay()
self.view.setNeedsLayout()
但它不起作用。
这是app的链接(只有一个视图控制器,< 200 SLOC) https://github.com/stanchiang/ParsingRSS
func feedParser(parser: MWFeedParser, didParseFeedItem item: MWFeedItem) {
var scrollView = UIScrollView()
scrollView = UIScrollView(frame: self.view.frame)
scrollView.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(scrollView)
let stackView = UIStackView(arrangedSubviews: restructureText(item.summary) as! [UIView])
stackView.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height * 6)
stackView.axis = UILayoutConstraintAxis.Vertical
stackView.distribution = UIStackViewDistribution.FillProportionally
scrollView.addSubview(stackView)
self.view.setNeedsDisplay()
self.view.setNeedsLayout()
var fullHeight:CGFloat = 0.0
for view in stackView.arrangedSubviews {
if view.isKindOfClass(UITextView) {
let tv:UITextView = view as! UITextView
print("textview: \(tv.frame.size)")
}
if view.isKindOfClass(UIImageView) {
let tv:UIImageView = view as! UIImageView
print("imageview: \(tv.frame.size)")
}
fullHeight += view.intrinsicContentSize().height
}
print("new:\(fullHeight) vs old:\(stackView.frame.height)")
scrollView.contentSize = stackView.frame.size
parser.stopParsing()
}