我想scrollView
在视图加载到屏幕时进行配置。但是在使用时内容大小没有按预期工作AutoLayout
。如果放置在ViewDidAppear
它按预期工作但我希望我的滚动视图配置ViewDidLoad
方法
@IBOutlet weak var addressScrollView: UIScrollView!{
didSet{
self.addressScrollView.pagingEnabled = true
self.addressScrollView.pagingEnabled = true
self.addressScrollView.showsHorizontalScrollIndicator = false
}
}
var billQuotes = ["This is bill","Bill Smokes","Bill drinks","But Still Codes"]
var viewFrame: CGRect = CGRectMake(0, 0, 0, 0)
override func viewDidLoad() {
super.viewDidLoad()
configureScrollView()
}
override func viewDidLayoutSubviews() {
self.addressScrollView.contentSize = CGSizeMake(self.addressScrollView.frame.size.width * CGFloat(billQuotes.count+1), self.addressScrollView.frame.size.height)
}
override func viewDidAppear(animated: Bool) {
//if placed in view did appear it works as expected but i want it to
}
func configureScrollView(){
for bill in billQuotes{
var index = find(billQuotes,bill)
viewFrame.size = self.addressScrollView.frame.size
viewFrame.size.width = self.addressScrollView.frame.size.width - 20
viewFrame.origin.x = ((self.addressScrollView.frame.size.width) * CGFloat(index!)) + 10
let addressView = UIView()
addressView.layer.borderWidth = 2.0
addressView.layer.borderColor = UIColor.grayColor().CGColor
addressView.layer.cornerRadius = 5
addressView.frame = viewFrame
addressView.backgroundColor = UIColor(red: 0.847, green: 0.847, blue: 0.843, alpha: 1.00)
var billLabel = UILabel(frame: CGRectMake(32, 8, addressView.frame.size.width - 34, 30))
billLabel.textAlignment = NSTextAlignment.Left
billLabel.text = "\(bill)"
billLabel.font = UIFont.systemFontOfSize(20)
billLabel.textColor = UIColor(red: 0.337, green: 0.341, blue: 0.345, alpha: 1.00)
addressView.addSubview(billLabel)
addressScrollView.addSubview(addressView)
}
}
已更新:我希望我的滚动视图在 viewDidLoad 中配置,以便在视图出现后的几分之一秒后立即看到