In my application, I have a large area (β5000x5000pts), and I should allow the user to see (+ scale, scroll) only my specific rectangular subdomain with sides not necessarily parallel to the sides of the area.
What is the best way to do this?
What am I doing now:
- You have a large
UIView containing the entire area (therefore, its frame is 5000x5000) as a UIScrollView subtitle. Calculate and apply CGAffineTransform - rotate my view so that the sides of the area are parallel to the coordinate axis and put the desired area at the origin:
contentView.transform = CGAffineTransformMake(cos(angle), sin(angle), -sin(angle), cos(angle), -requiredRect.origin.x, -requiredRect.origin.y);
Set the size of the scroll content to the desired value.
scrollView.contentSize = CGSizeMake(someWidth, someHeight);
It works in some way, but there are some (not all of the above actually) problems with it:
- When I zoom in on the scroll, its content size is reset to the size of my large area view (5000x5000 times the zoom factor). I set it again in the
scrollViewDidEndZooming delegate scrollViewDidEndZooming , but it still looks weird. - Zooming appears to be applied from the wrong anchor point and does not look beautiful (the view βjumpsβ to another position after scaling is complete)
Can you suggest a different approach to the problem or indicate what can be done to improve my current? It seems that UIScrollView is behaving badly when custom transformations are applied to its content views ...
source share