我創建了一個非常簡單的細節視圖,有幾張圖片,用戶可以通過頂部進行翻頁,並在底部的項目名稱上有一些細節。但是我的滾動視圖沒有頁面到正確的地方,像這樣:UIScrollView無法分頁正確的距離
我的滾動視圖的框架&其子視圖的框架設置如下:
override func viewDidLoad() {
super.viewDidLoad()
self.pictures.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height/CGFloat(2))
self.pictures.clipsToBounds = false
let width = pictures.frame.width
let height = pictures.frame.height
/*
let view1 = UIView(frame: CGRectMake(pictures.frame.origin.x, 0, scrollViewWidth, scrollViewHeight))
let view2 = UIView(frame: CGRectMake(pictures.frame.origin.x + scrollViewWidth, 0, scrollViewWidth, scrollViewHeight))
let view3 = UIView(frame: CGRectMake(pictures.frame.origin.x + scrollViewWidth * 2, 0, scrollViewWidth, scrollViewHeight))
let view4 = UIView(frame: CGRectMake(pictures.frame.origin.x + scrollViewWidth * 3, 0, scrollViewWidth, scrollViewHeight))
*/
for index in 0...2 {
let frame = CGRectMake(width * CGFloat(index), 0, width, height)
let view = UIView(frame: frame)
views.append(view)
pictures.addSubview(view)
}
views[0].backgroundColor = UIColor.redColor()
views[1].backgroundColor = UIColor.blueColor()
views[2].backgroundColor = UIColor.orangeColor()
pictures.delegate = self
pictures.contentSize = CGSizeMake(width * CGFloat(views.count), height)
}
有沒有人有任何建議,我怎麼能適應這個?我是否錯誤地實現了我的滾動視圖?
你有沒有考慮過使用'UICollectionView'而不是'UIScrollView'? – Magoo
如何將幻燈片類型接口與UICollectionView結合? –
'UICollectionView'基於'UIScrollView',因此具有'pagingEnabled',它也可以水平滾動使用它的流佈局 – Magoo