我的功能滚动中的图像奇怪地出现在较小尺寸的手机中,例如iPhone 5s
、iPhone 6
等。
编辑:我UIScrollView
用来做这个。:)
我尝试将我的代码添加到viewDidLayoutSubviews
其中,viewWillLayoutSubviews
但它似乎不起作用。
//第一次尝试
override func viewDidLayoutSubviews() {
featureScroll.contentSize = CGSize(width: self.view.bounds.width * CGFloat(featureArray.count), height: 300)
}
//第二次尝试
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()()
featureScroll.contentSize = CGSize(width: self.view.bounds.width * CGFloat(featureArray.count), height: 300)
}
编辑://我如何将图像加载到 featureScroll
let feature1 = ["image": "ic_home1"]
let feature2 = ["image": "ic_home2"]
let feature3 = ["image": "ic_home3"]
var featureArray = [Dictionary<String, String>](
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
featureArray = [feature1, feature2, feature3]
featureScroll.isPagingEnabled = true
featureScroll.contentSize = CGSize(width: self.view.bounds.width * CGFloat(featureArray.count), height: 300)
featureScroll.showsHorizontalScrollIndicator = false
featureScroll.delegate = self
loadFeatures()
}
func loadFeatures(){
for (index, feature) in featureArray.enumerated() {
if let featureView = Bundle.main.loadNibNamed("Feature", owner: self, options: nil)?.first as? FeatureView {
featureView.featureImage.image = UIImage(named: feature["image"]!)
featureScroll.addSubview(featureView)
featureView.frame.size.width = featureScroll.bounds.size.width
featureView.frame.origin.x = CGFloat(index) * featureScroll.bounds.size.width
}
}
}
func scrollViewDidScroll(_ featureScroll: UIScrollView) {
let page = featureScroll.contentOffset.x / featureScroll.frame.size.width
featurePageControl.currentPage = Int(page)
}
下面的链接显示了实际结果,我想摆脱空白,我应该怎么做?
--> https://imgur.com/8AUZh4U.png
预先感谢您的帮助!:)