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.
Related
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.
I have a UIScrollView of size 320*460 and with content size 1024*1024.
I can place 25 images of 256*256 in it with the 13th picture shown at the centre of the
screen when it loades with bits of surrounding pictures around it.
When i swipe to any side I want it to appear just like the mapView. With new images
appearing and showing.
How can I do it?
It's very easy & somewhat tricky...
You don't need to define the specific size for the ScrollView.....
Generally we use to define ....as per the Examples of Apple
//#define SCROLLVIEW_CONTENT_HEIGHT 460
//#define SCROLLVIEW_CONTENT_WIDTH 320
which is of no use...if you need the infinite height..
just set the height of the ScrollView dynamically as per the Objects added to the ScrollView....
No need to set the predefined height for this...take the dynamic height....
scrollview.contentSize = CGSizeMake(320, txtView.contentSize.height+450);
CGPoint topOffset = CGPointMake(0,0);
[scrollview setContentOffset:topOffset animated:YES];
Hope this will surely work for you..
Good Luck :)
Checkout the sample code called 'Tiling'. It might be what you're looking for.
When scrolling stops, couldn't you just adjust the bounds so that you are now "re-centered" with your new offset?
Presumably you can't scroll more than so many pixels before your finger hits the edge of the screen, so you only need bounds that a few hundred pixels outside the original center.
Once you have a new center, adjust your bounds accordingly, retiling as necessary.
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;
I have a subview inside a uiscrollview. Then I zoom it out. So it becomes bigger and allows me to scroll through it.
So what is actually changing here? ContentSize of UIScrollView?
If you are not manually responding to changes in the zoom scale (like I describe in this answer), the view that you return from the -viewForZoomingInScrollView: delegate method is simply having a scaling transform applied to it by the UIScrollView. The frame size of the view is not changing, it is just being graphically transformed (which is why you see blurriness at higher scale factors).
The content size of the scrollview remains logically the same. If you check the frame of the scroll view it remains the same.
I think all that is changing is the scaling of the CGLayers. When you zoom in, it shrinks the clipping region frame smaller but then scales the CGLayer transform upwards. In other words, all the logical elements are still present it is simply choosing to draw and display a different part of it.
In the iPhone Application Programming Guide they have a good explanation about the relationship between frames, clipping regions and various transforms on views.
I have a UIScrollView of size 320*460 and with content size 1024*1024.
I can place 25 images of 256*256 in it with the 13th picture shown at the centre of the
screen when it loades with bits of surrounding pictures around it.
When i swipe to any side I want it to appear just like the mapView. With new images
appearing and showing.
How can I do it?
It's very easy & somewhat tricky...
You don't need to define the specific size for the ScrollView.....
Generally we use to define ....as per the Examples of Apple
//#define SCROLLVIEW_CONTENT_HEIGHT 460
//#define SCROLLVIEW_CONTENT_WIDTH 320
which is of no use...if you need the infinite height..
just set the height of the ScrollView dynamically as per the Objects added to the ScrollView....
No need to set the predefined height for this...take the dynamic height....
scrollview.contentSize = CGSizeMake(320, txtView.contentSize.height+450);
CGPoint topOffset = CGPointMake(0,0);
[scrollview setContentOffset:topOffset animated:YES];
Hope this will surely work for you..
Good Luck :)
Checkout the sample code called 'Tiling'. It might be what you're looking for.
When scrolling stops, couldn't you just adjust the bounds so that you are now "re-centered" with your new offset?
Presumably you can't scroll more than so many pixels before your finger hits the edge of the screen, so you only need bounds that a few hundred pixels outside the original center.
Once you have a new center, adjust your bounds accordingly, retiling as necessary.