UIScrollView zoom after rotation - iphone

Allright, i have a UIScrollView with some drawings inside. the zoom and scroll works fine until i zoom in and then rotate. after the rotation zoom is fine but when i zoom back my drawings shrink more than i intend them to.
So basically, when i zoom out after rotation the view gets smaller than the screen.. how can i fix this problem ? any idea ?
I tried _scrollView.clipsToBounds = YES; but not working after the rotation.
Thanks

Have you tired to set min/max zoom scale on the UIScrollView ? Assuming you have a reference to the UIScrollView you can set the minimum zoom scale. This will ensure that when you zoom out you drawings won't shrink more than you want.
scrollView.minimumZoomScale = 1.00;

Related

UIScrollView. How Can I Tell Zoom Out From Zoom In?

On iOS I have a UIScrollView subclass. During a zoom gesture I need to distinguish zoom-out from zoom-in. What is the best way to do this?
Thanks,
Doug
In UIScrollViewDelegate's scrollViewWillBeginZooming:withView:, store the current zoomScale of your UIScrollView; compare the stored value to the zoomScale in the scrollViewDidEndZooming:withView:atScale: to determine if it was a zoom in or a zoom out. If the value has increased, it was a zoom in; otherwise, it was a zoom out.

How can I have pinch zoom and two-finger rotation at the same time on an UIImageView?

I have an Image View and I need to be able to pinch-zoom it, scroll it when it is zoomed and also rotate it with two-finger.
Initially I used a scrollView and added ImageView to it. but ImageView wasnt getting rotation gestures as ScrollView was intercepting them.
So I added the gesture to the ScrollView started rotating the scrollView itself.
Things work fine but rotated scrollView doesn't look good.
So I made the ScrollView get the rotation gesture but rotated the imageView in it instead of ScrollView.
But Now, the problem is If I rotate the image and then zoom and again try to rotate, previous rotation is lost and same when I rotate the previous zoom level is lost.
How should I go about it ? Is the scrollView unnecessary ?

content size of UIScrollView

I have a UIScrollView in which I've set the contentSize to the size of the screen initially. So does this mean that if I have an UIImageView inside the scroll view then it can't zoom bigger than the contentSize I've set?
Because I initially have a UIScrollView with a contentSize of the phone's dimension and when I zoom into an image, it does it just fine (I can see the contentSize grows bigger as I zoom in) but when I adjust it manually it can't. Why is this?
I think when I initially initialize the UIScrollView frame, the content size will be set to the frame's size, however it can grow dynamically as I zoom in. However when I try to set the contentSize, it seems that now it's fixed. The reason why I am asking this is because I have a UIImageView inside a UIScrollView, when I zoom in on the image and I rotate the image, I want the contentSize to reset. Question is how do I reset this?
The zoom level is set by the zoomScale property of the UIScrollView. Its maximum and minimum is set by maximumZoomScale and minimumZoomScale respectively.
If you're trying to set the zoom by setting the contentSize then you're doing it wrong. The contentSize should be set as if the zoom scale was 1.0 and then you'd just set the zoomScale property to be what you wanted so for example 2.0 if you wanted it zoomed in to 200%.
You're probably seeing contentSize change as you zoom because I think the scroll view reports it scaled to the current zoom scale.

UIScrollView zoomToRect vs setZoom

If I have a UIScrollView, and I want to zoom in on a location, is there any difference between just setting the zoom on scrollview like
self.scrollView.zoomScale = MY_NEW_ZOOM;
versus calculating a new rectangle within the zoom to zoom in on, and using
zoomToRect:
Thanks.
zoomScale just sets the zoom scale and doesn't change the content offset.
zoomToRect: will change the zoom scale and the content offset such that the rect you have given will be visible.
Just as a heads up, you may want to ensure that the size of the rect you pass in zoomToRect: is the size of the scrollview's frame. Otherwise the Zoom and Content Offset might not end up where you expect it.

UIView parent window's frame and bound dimensions while rotating iPad

I a have a following line of code invoked after a touch gesture has completed:
CGRect parentBounds = self.view.bounds;
CGRect parentFrame = self.view.frame;
when iPad is placed in a vertical way both parentFrame and parentBounds have similar dimensions of w:768 h:1004 (or something close to that), but when I rotate parentBounds is 1024x748 while parentFrame is 768x1024.
Is this behavior normal? I thought I understood the concepts beetwen frames and bounds (and how they relate to each other)... but now I am really confused.
Could anyone explain what is happening with frame and bounds of a window (superview) when rotation occurs?
The window does not change orientation; the root view does. It does this by applying a view transform (self.view.transform). You're not supposed to call frame if transform is not CGAffineTransformIdentity.
This is not a complete answer, but might help if you don't get something better: When the device is rotated, the top-level window's frame does not change. Instead, a transform gets applied that rotates everything 90 degrees (or 180 degrees), and then the subviews will get resized to fit in the new coordinate system.
From Apple's PhotoScroller sample code:
We have to use our paging scroll view's bounds, not frame, to calculate the page placement. When the device is in landscape orientation, the frame will still be in portrait because the pagingScrollView is the root view controller's view, so its frame is in window coordinate space, which is never rotated. Its bounds, however, will be in landscape because it has a rotation transform applied.
In short, the view's frame is not affected by device rotations, but its bounds is.