Now I have the following view hierarchy:
My view hierarchy is a little complicated, because I need both scale and rotation, and I also need to keep the map position and arrows connected, I worked for a long time and found this solution.
Now My question is, how to Arrow Image Viewalways save in the center of the screen when scaling?
Here is my code:
func viewForZooming(in scrollView: UIScrollView) -> UIView? {
return Container For Scale View
}
func scrollViewDidZoom(_ scrollView: UIScrollView) {
let imageViewSize = MapImageView.frame.size
let scrollViewSize = scrollView.bounds.size
let verticalPadding = imageViewSize.height < scrollViewSize.height ? (scrollViewSize.height - imageViewSize.height) / 2 : 0
let horizontalPadding = imageViewSize.width < scrollViewSize.width ? (scrollViewSize.width - imageViewSize.width) / 2 : 0
scrollView.contentInset = UIEdgeInsets(top: verticalPadding, left: horizontalPadding, bottom: verticalPadding, right: horizontalPadding)
}
source
share