Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix image zoom center issue #390

Merged
merged 1 commit into from Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sources/Mantis/CropView/CropView+UIScrollViewDelegate.swift
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