Skip to content

Commit

Permalink
Merge pull request #102 from boostcampwm-2024/fix/#100-fix-content-co…
Browse files Browse the repository at this point in the history
…nstraints

[FIX/#100] 스크롤뷰 컨텐츠 센터링 + 줌 문제 해결
  • Loading branch information
0Hooni authored Nov 26, 2024
2 parents b9a58ec + 9d8613c commit 031aab0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ final class CanvasScrollView: UIScrollView {

func updateFrameImage(to image: UIImage) {
imageView.image = image
imageView.sizeToFit()

self.imageView.sizeToFit()
self.setupZoomScale()
self.contentCentering()
}

func contentCentering() {
Expand Down Expand Up @@ -62,14 +65,14 @@ final class CanvasScrollView: UIScrollView {
let heightBaseScale = frame.height / image.size.height
let calculatedZoomScale = min(widthBaseScale, heightBaseScale)

zoomScale = calculatedZoomScale
// 호출 순서 바꾸면 안됨
minimumZoomScale = calculatedZoomScale
zoomScale = calculatedZoomScale
}
}

extension CanvasScrollView: UIScrollViewDelegate {
public func viewForZooming(in scrollView: UIScrollView) -> UIView? {
contentCentering()
return imageView
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ public class EditPhotoRoomGuestViewController: BaseViewController, ViewControlle
bindOutput()
}

public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

canvasScrollView.setupZoomScale()
canvasScrollView.contentCentering()
}

public func addViews() {
[navigationView, canvasScrollView, bottomView].forEach {
view.addSubview($0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ public class EditPhotoRoomHostViewController: BaseViewController, ViewController
bindOutput()
}

public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()

canvasScrollView.setupZoomScale()
canvasScrollView.contentCentering()
}

public func addViews() {
[navigationView, canvasScrollView, bottomView].forEach {
view.addSubview($0)
Expand Down Expand Up @@ -82,8 +75,6 @@ public class EditPhotoRoomHostViewController: BaseViewController, ViewController
navigationView.backgroundColor = .yellow
bottomView.backgroundColor = .yellow
canvasScrollView.backgroundColor = .red

canvasScrollView.imageView.sizeToFit()
}

public func bindInput() {
Expand Down

0 comments on commit 031aab0

Please sign in to comment.