UIScrollview zoom and enable paging simultaneously - iphone

Can i implement both the paging and zooming of imageview in a uiscrollview at the same time.

Yes. You can do it.
In each page of the mainScrollView add a subScrollView containing the imageView. You need to do the following things.
Set maximumZoomScale for subScrollView
[subScrollView setMaximumZoomScale:2.0f]; // You can set any value
This value is calculated based on the size of the image displayed in the imageView.
In the viewForZoomingInScrollView: method of the subScrollView return the imageView
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return imageView;
}
Enable paging in mainScrollView
mainScrollView.pagingEnabled = YES;
You have to write further code to handle paging in the mainScrollView.

Related

issue while zooming content of UIScrollView

i am developing an application in which i am placing a set of images on a scrollView.i could place the images and given the contentSize as required to fit all the number of images.each imageView is of size 768,1024.i set the property of pagingEnabled to YES on the scrollview,to move to next image as the user swipes. i am loading each image into the imageview on scrolling the scrollView. i.e - (void)scrollViewDidScroll:(UIScrollView *)scrollView{
issue:
the issue i face is when i zoom a UIImageView the imageView is getting zoomed but the zoomed imageView is being overlapped by its next imageView with its size assigned i.e 768,1024. i included the delegate methods as below.
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return [scrollView viewWithTag:tempTag-1];
}
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view{
scrollView.pagingEnabled=NO;
[scrollView viewWithTag:tempTag].frame=CGRectMake(scrollView.contentSize.width-768, [scrollView viewWithTag:tempTag].frame.origin.y, [scrollView viewWithTag:tempTag].frame.size.width, [scrollView viewWithTag:tempTag].frame.size.height);
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale{
if (scrollView.zoomScale<=1) {
scrollView.pagingEnabled=YES;
}
}
i tried to change the frame of the next imageView to current ImageView depending on the content size but it didn't work.
can some one help me in this regard..
TNX in advance
You need to create a scrollView of sub-scrollviews to hold the imageViews. Then configure zoom on each sub-scrollviews.

Making UIScrollView to both scroll and zoom

I am having some troubles making my UIScrollView to exhibit both scrolling and zooming. My class (which sub-classes UIScrollView) has a UIView as a sub-view, and in this sub-view I draw on a CALayer. As soon as the app launches, I can scroll the view, but as soon as I zoom using the pinch gesture, the scrolling feature stops working, and only the zoom works. My code:
bpmGraphView = [[UIView alloc] init];
//--- configure the scroll-view and add the graph-view as a subview
[self setZoomScale:1.0];
[self setContentSize:CGSizeMake(1000.0, 169.0)];
[self setMultipleTouchEnabled:YES];
[self setScrollEnabled:YES];
self.maximumZoomScale = 20.0;
self.minimumZoomScale = 0.05;
self.clipsToBounds = YES;
self.delegate = self; //--- set the scroll-view delegate to self
[self addSubview:bpmGraphView];
And the delegate method:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView{
return [self bpmGraphView];
}
Any ideas?
EDIT
Some dimensions: My UIScrollView is 320x169 and it is positioned 7 pixels to the right of the left edge of the screen. The (scrollable) UIView inside it should have the same height, but start 30 pixels to the left of the UIScrollView, and end somewhere far to the right - 1000 is just a test number. The sublayer I add to UIView should have the same size and position as it's superview.
I will init the UIView with the proper frame and report any changes in the behavior of the app.
at a first look i just notice a big ContentSize width and a small height... are you sure you need it to be 1000 x (just) 169?
And which are the dimensions of bpmGraphView?
And why don't you init bpmGraphView with a dimension? It's a UIView, you should init it giving it a frame, with initWithFrame:, not just init.
And also: give us the dimension of your UIScrollView, the only dimension you give us is the UIScrollView.contentSize...
Refer this apple sample code, it contains everything about scrollview
http://developer.apple.com/library/ios/#samplecode/ScrollViewSuite/Introduction/Intro.html

How to have images that do not resize when zooming in a UIScrollView?

I want to have images inside of a UIScrollView (or at least appear to be inside a UIScrollView) that don't change their size when zooming in and out. I do want the images to maintain their positions when zooming or scrolling.
The use case is that I have a customized map view with pushpins. I want the pushpins to stay in place when zooming and scrolling the map, but I don't want them to be "zoomed in" with the content.
What is the best way to do this?
You can have your pushpin image(s) as a subview of your UIScrollView but not a subview of the view returned by
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
Then, in scrollViewDidZoom adjust the pushpin x and y by the zoomScale to keep the pins correctly positioned:
- (void)scrollViewDidZoom:(UIScrollView *)scrollView {
imageView.frame = CGRectMake(pushPinX * scrollView.zoomScale, pushPinY * scrollView.zoomScale, imageView.frame.size.width, imageView.frame.size.height);
}

Properly zooming a UIScrollView that contains many subviews

I created a zoomable UIScrollView and added 100 subviews to it (tiled). The view scrolls perfectly left and right. However, I'd like to allow zooming.
To do so I read that my delegate needs to implement:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return ???;
}
I have seen examples that have only one subview to zoom, so they return that subview in that method. In my case, however, I have a lot more. What is the proper way to do the zooming?
I tried creating another UIView and adding the 100 subviews to that one. And then return that one view on the method above, but I doesn't work (it zooms but once it stops, it's not interactive any more).
Exactly,
This is what Apple also is mentioning in the Scroll View Programming Guide:
Just create a view, add all subviews to this view and add the newly created view as a single subview to the scrollview...
Then in the viewForZoomingInScrollView delegate method return the object at Index 0:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return [self.scrollView.subviews objectAtIndex:0];
}
I created the view where I added everything using:
UIView *zoomableView = [[UIView alloc] init];
without setting its frame.
The problem was solved when, after adding all the subviews to it, I set its frame to something large enough to accommodate all the tiled subviews.
You have to return what your going to add views to scroll view as a subviews.
Ex: If you are adding image view to scroll view then write
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return imageView object;
}

Updating zoomScale of UIScrollView

I just created an animation to zoom in or zoom out a UIScrollView, but my problem is that the zoomScale is not updating. Like for example, I zoom out my UIView inside of my UIScrollView using the animation I created, but when I zoom in using expand gesture the UIView will automatically change to its big size or zoom in size. I saw the my zoomScale is not updating and still in 1.0 scale. Then I update my zoomScale after the animation but the problem is the zoom out UIView will automatically go to the top of the screen. Can I update this zoomScale property of UIScrollView?
Thanks.
Did you implement viewForZoomingInScrollView function ?
This function of your scroll view delegate is called when you change the zoomScale. It returns the view that must be rescaled when the scale of your scrollview is changed.
In general you just return the scrollView given in parameters :
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView; {
return scrollView.childView;
}
Don't forget to set a delegate to your scrollview : yourScrollView.delegate = self;