我有一个UIImageView在一个UIScrollView,我希望能够滚动到“常规”照片维度的维度。我的问题是,我可以滚动,但是当它到达照片的顶部或底部时,滚动的位置不会停留,相反,它会“反弹”,移动一点点,不允许照片停留在那个位置,我该如何修复这个问题呢?
以下代码如下:
scrollView.frame = CGRect(x: self.view.frame.width * 0, y: self.view.frame.height / 3, width: self.view.frame.width, height: self.view.frame.width)
self.view.addSubview(scrollView)
scrollView.delegate = self
let image = imageView.image
imageView.frame = CGRect(x: self.view.frame.width * 0, y: self.view.frame.height * 0, width: (image?.size.width)!, height: (image?.size.height)!)
imageView.frame = scrollView.bounds
imageView.contentMode = .scaleAspectFill
scrollView.addSubview(imageView)举个例子,如果你用相机拍摄了一张全屏照片,然后当照片在视图中显示时,当它被滚动时,整个照片就不能停留在它的位置上。
发布于 2017-08-25 20:04:20
您做了许多错误的事情,正如前面提到的,您应该移动到自动布局和约束,但是.
为了让你的图像像你要做的那样滚动:
// set scroll view frame to be full width of view, start 1/3 of the way down from the top, and make the height the same as the width
scrollView.frame = CGRect(x: 0, y: self.view.frame.height / 3, width: self.view.frame.width, height: self.view.frame.width)
// add the scroll view to the view
self.view.addSubview(scrollView)
// use "if let" so you're not force-unwrapping optionals
if let image = imageView.image {
// set the imageView's frame to the size of the image
imageView.frame = CGRect(x: 0, y: 0, width: image.size.width, height: image.size.height)
// add the imageView to the scroll view
scrollView.addSubview(imageView)
// set the contentSize of the scroll view - the "scrollable area" - to the size of the image view
scrollView.contentSize = imageView.bounds.size
}发布于 2017-08-25 19:44:32
弹出是UIScrollView (及其子类,包括UiTableView)中的一种可选行为。您可以通过弹跳财产或Interface打开/关闭它。
我通常将所需的ScrollView属性捆绑在一个方便的方法(或者您可以使用UIAppearance)中,以确保我的所有视图都具有共享行为。
https://stackoverflow.com/questions/45888339
复制相似问题