In my application I have large area (≈5000x5000pts) and I must allow user to see (+zoom, scroll) only its certain rectangular subregion with sides not necessarily parallel to area sides.
What is the best way to accomplish that?
What I am doing now:
- Have a large
UIView
containing whole area (so its frame is 5000x5000) as a UIScrollView's subview. Calculate and apply
CGAffineTransform
- rotate my view to make region sides parallel to the coordinate axis and position required area to the origin:contentView.transform = CGAffineTransformMake(cos(angle), sin(angle), -sin(angle), cos(angle), -requiredRect.origin.x, -requiredRect.origin.y);
Set scrollview's content size to required value.
scrollView.contentSize = CGSizeMake(someWidth, someHeight);
It works in a way but there're some (not all listed in fact) problems with it:
- When I zoom the scroll view its content size resets to the size of my large area view (5000x5000 multiplied by scale factor). I set it again in delegate's
scrollViewDidEndZooming
method but it looks weird anyway. - Zooming seems to be applied with incorrect anchor point and looks not nice (view "jumps" to another position after zooming is finished)
Can you propose another approach to the problem or point what can be done to improve my current one? It looks that UIScrollView
behaves badly when custom transforms are applied to its content views...