Skip to content

Commit

Permalink
fix: fix image zoom center issue (#390)
Browse files Browse the repository at this point in the history
use image center as zoom center
  • Loading branch information
guoyingtao authored Apr 10, 2024
1 parent e08e341 commit c0f892c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Sources/Mantis/CropView/CropView+UIScrollViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ extension CropView: UIScrollViewDelegate {
viewModel.setTouchImageStatus()
}

func scrollViewDidZoom(_ scrollView: UIScrollView) {
guard scrollView.subviews.count > 0 else {
return
}

let subView = scrollView.subviews[0]

let offsetX: CGFloat = max((scrollView.bounds.size.width - scrollView.contentSize.width) * 0.5, 0.0)
let offsetY: CGFloat = max((scrollView.bounds.size.height - scrollView.contentSize.height) * 0.5, 0.0)

subView.center = CGPointMake(scrollView.contentSize.width * 0.5 + offsetX, scrollView.contentSize.height * 0.5 + offsetY)
}

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
viewModel.setBetweenOperationStatus()
}
Expand Down

0 comments on commit c0f892c

Please sign in to comment.