我有一個UIScrollView水平滾動啓用分頁。有什麼辦法可以改變滾動視圖的分頁,以便在滾動視圖的整個長度上對齊一半。我添加了顯示我在找什麼的圖片。自定義分頁UIScrollView
override func viewDidLoad() {
super.viewDidLoad()
let scrollView = UIScrollView()
scrollView.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: self.view.frame.size.height)
scrollView.contentSize = CGSize(width: self.view.frame.size.width * 2, height: self.view.frame.size.height)
scrollView.isPagingEnabled = true
self.view.addSubview(scrollView)
let view1 = UIView()
view1.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width/2, height: self.view.frame.size.height)
view1.backgroundColor = UIColor.purple
scrollView.addSubview(view1)
let view2 = UIView()
view2.frame = CGRect(x: self.view.frame.size.width/2, y: 0, width: self.view.frame.size.width/2, height: self.view.frame.size.height)
view2.backgroundColor = UIColor.green
scrollView.addSubview(view2)
let view3 = UIView()
view3.frame = CGRect(x: self.view.frame.size.width, y: 0, width: self.view.frame.size.width/2, height: self.view.frame.size.height)
view3.backgroundColor = UIColor.yellow
scrollView.addSubview(view3)
let view4 = UIView()
view4.frame = CGRect(x: self.view.frame.size.width + self.view.frame.size.width/2, y: 0, width: self.view.frame.size.width/2, height: self.view.frame.size.height)
view4.backgroundColor = UIColor.red
scrollView.addSubview(view4)
}
請詳細說明,並顯示您的代碼 –
我有一個滾動視圖覆蓋整個屏幕和滾動視圖內的四個視圖。這四個子視圖中的每一個都具有寬度的一半。我想這個滾動視圖捕捉到下一個子視圖(這是屏幕寬度的一半)。我會附上一段視頻和我的代碼來展示我已經構建的內容。 –
以下是視頻:https://drive.google.com/file/d/0B6E9tiTyLokuRmVjelRmVWgzbHc/view?usp =分享 –