後我的影響:有圖像之間的間距,同時滾動(如照片應用程序)是唯一可見的。保證金 - 斯威夫特版本
很多老OBJ-C答案建議延長屏幕外滾動視圖的邊界,使其頁面更遠,並且使這個屏幕外空間圖像之間的差距。
爲pagingEnabled文檔狀態:
如果此屬性的值是YES,滾動視圖上停止滾動視圖的邊界當用戶滾動的 倍數。
因此,在試圖更改倍數值時,我擴展了scrollView的寬度,並啓用了左側分頁。然而,沒有答案,我實現過去的差距頁面 - 他們總是把它留在視圖:
所以如果滾動寬度較長,爲什麼沒有分頁適當的距離?
let gapMargin = CGFloat(20)
scrollView.frame = CGRect(x: 0, y: 0, width: view.frame.width + gapMargin, height: view.frame.height)
let exdScrollWidth = scrollView.frame.width
//1
let imageView1 = UIImageView()
imageView1.backgroundColor = UIColor.green
imageView1.frame = CGRect(x: 0, y: 0, width: exdScrollWidth - gapMargin, height: scrollView.bounds.size.height)
//2
let imageView2 = UIImageView()
imageView2.backgroundColor = UIColor.yellow
imageView2.frame = CGRect(x: exdScrollWidth, y: 0, width: exdScrollWidth - gapMargin, height: scrollView.bounds.size.height)
//3
let imageView3 = UIImageView()
imageView3.backgroundColor = UIColor.red
imageView3.frame = CGRect(x: exdScrollWidth * 2, y: 0, width: exdScrollWidth - gapMargin, height: scrollView.bounds.size.height)
scrollView.contentSize.width = exdScrollWidth * 3
scrollView.addSubview(imageView1)
scrollView.addSubview(imageView2)
scrollView.addSubview(imageView3)
感謝您的回覆。我已經盡力實現這一點 - 也許你可以證明它是如何完成的。 – Tim
添加了截屏視頻,演示。每個圖像視圖都有一個邊框,因此您可以看到它們之間確實存在差距。這是我的答案中所描述的_exactly_創建的。 – matt
我看到它是你描述的,但請記住它不是我描述的問題。我所包含的代碼是我的嘗試,如果您提到它,它會很有幫助。 – Tim