0
我有一個UIScrollView,裏面有UIImageView。只是一個簡單的測試用例:UIImageView是滾動視圖的整個寬度並且以自動佈局爲中心到Y.然而,在我的設備上的最終結果並不是真正以Y爲中心。在UIScrollView中縮放UIImageView - 不居中
但我遇到這樣的問題,即使用滾動視圖縮放UIImageView時,它會「漂移」到底部區域 - 不僅僅是在中心縮放因爲它應該是。當縮小(在視頻的最後)時,它也會「向左移動」並彈回中心。
我做了此行爲的小預覽視頻:https://www.youtube.com/watch?v=ivRNkzNrcEA
這裏是我的簡單的測試代碼:
class TestController: UIViewController, UIScrollViewDelegate {
@IBOutlet weak var SCROLL: UIScrollView!
@IBOutlet weak var IMAGE: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
SCROLL.minimumZoomScale = 1;
SCROLL.maximumZoomScale = 6.0;
SCROLL.zoomScale = 1.0;
SCROLL.contentSize = IMAGE.frame.size;
SCROLL.delegate = self;
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
}
func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView? {
return IMAGE
}
func scrollViewDidZoom(scrollView: UIScrollView) {
}
func scrollViewDidEndZooming(scrollView: UIScrollView, withView view: UIView?, atScale scale: CGFloat) {
}
}
這裏是我測試的自動佈局: