后我的影响:有图像之间的间距,同时滚动(如照片应用程序)是唯一可见的。保证金 - 斯威夫特版本
很多老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