Stop scroll image in UIScrollView when image zoom - iphone

I have a image in UIScrollView, I wants user cannot scroll image in zoom time, I read many property of UIScrollView, but I am confused.
How we stop scrolling image(horizontally or vertically) when user zoom the image in scrollView.
I already test
scroll.scrollEnabled=NO;
scroll.directionalLockEnabled = YES;
scroll.bounces=NO;
scroll.scrollEnabled = N0; stop scrolling but the task is that the user cannot scroll the image ,when user zoom the image , I need help
Thanks

You have to set your viewcontroller as scrollviews delegate. Assuming you have UIImageView that you are zooming in scrollView. What you want to do is to center it in the middle of scrollviews bounds while zooming. If you only want to disable scrolling in vertical or horizontal direction then change only x or y center of imageView
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
self.imageView.center=CGPointMake(CGRectGetMidX(self.scrollView.bounds), CGRectGetMidY(self.scrollView.bounds));
}
I highly recommend having a look at apple video session on advanced scrollview techniques 2010, 2011 and 2012 they really explain quite well what a powerful beast UIScrollView really is. Hope this was helpful

Related

Possible to Limit Zooming / Panning Area in UIScrollView?

I have a UIViewController that implements a UIScrollView with the UIScrollViewDelegate. Attached to it is an UIImageView for which the user must crop the photo via zooming it and panning to fill the entire length of the screen. After the user has finished cropping and they hit done, the original UIImage gets sent to the next UIViewController.
I'm wondering, is there anyway, using the original image, to display it in a UIScrollView and allow the user to zoom and pan it so ONLY the cropped area gets shown? IE none of the image that was outside of the cropped area gets shown in zooming and panning? Is there a way to do this without explicitly cropping the image?
This might head you in the right direction: Displaying part of an image
Not to sure if this will work with the way you are displaying it. But if it does it could be a simple solution. You can also read through UIScrollviews and maybe use panGestureRecognizer and pinchGestureRecognizer to limit the area they can zoom and pan.
Set the content size of the UIScrollView to the rect of the cropped area.

Uiimageview inside uiscrollview position is not centered

I am developing an app for iPhone/iPad using Objective C. In my app I am having an UiScrollView which is having an UIImageView inside it. I can scroll and Zoom the Image inside the Scroll View.
All works fine.But my problem is that when I am loading the Image Inside a uiscrollview, its position is at something at center but not exactly.
I want that either my image should be center aligned or at the Top Left corner.
I had set the contentoffset to (0,0) and also tried setting the AutoresizingMask to different values.
Please let me know if somebody has any idea or solution.
contentoffset is something of the scrollview and is probably not right for this situation. If you want the image to be in the center do this:
imageview.center = scrollview.center;
If you want the image to be at the top left corner of the scrollview do this:
imageview.frame = CGRectMake(0,0,image_width,image_height);
Good luck!

adding a UIView on a UIScrollVIew during the zoom mode

i'm trying to place a UIView on a scrollView during its zoomed state. I want the UIView to be seen on the scrollView and also to resize along with it once the scrollView is zoomed out.. i am able to place the UIView on scrollView during the zoomed state. But the UIView is not getting resized after zooming out... Should i apply any transforms here??? can anyone help me in this please... Thank you
You can use a little trick: before zoom is started get the screenshot of the view (with subviews) that you want to zoom. Add that image to the UIImageView add return it via viewForZoomingInScrollView:. So you actually zoom the image of that view and not the one itself.
After zoom ended scale your actual view manually.
You can find out how to get screen shot from my post here

iPhone ScrollView zoom problems

I'm new to iPhone dev and Obj-C and I have several problems with ScrollView/ImageView while getting close to deadline. I used IB to create interface so I access most parameters via builder.
1) I was using touch events (begin/moved/ended) on imageView to switch images. When I put ImageView to ScrollView the old gestures stopped working and I can only zoom. If scrollView of both have focus I can't use my gestures even when zoomed out. How can I use both?
2) How do I zoom only image part of view? Unfortunately I also see background area around :/ What's worse - after rotating the view keeps it's old dimensions and I have even more black areas around image. For some reason image is in top-left corner.
Code snippets I found doesn't really help me much in this case. I have various images of different sizes in imageView to switch and zoom in/out.
EDIT: Ok, a little different. How do I override scrollview touch mode so that when image is zoomed out (to screen size) "normal" gestures would work. Currenly I have either scroll view scrolling or gestures, can't use both. Anyone?
Solved by dynamically changing imageview to imagesize and switching like:
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale {
if (scrollView.zoomScale==1.0) {
scrollView.userInteractionEnabled = NO;
imageView.userInteractionEnabled = YES;
}
Not the best solution but works good enough.

Iphone Custom Scrollview indicator

I am currently working on an application for a client, and they have made an odd request. The request involves putting a custom image as the indicator for the scrollview. I am not even sure if this is possible but if it is can you please let me know how one would go about doing that.
Thanks
UIScrollView streches a small, semi-transparent circle image to generate its scrollbars. You can find this image as the first subview of a UIScrollView:
UIImageView *circle = [scrollView.subviews objectAtIndex:0];
However, as I said this image is stretched, and as far as I can tell, only the alpha values are considered when drawing the scroll bars.
So for example if you're only interested in changing the top/bottom ends of the scroll bar, you can try to change this image. However, I doubt you'll be able to do anything interesting.
A possible solution that comes to mind, and this is only a theory, is to add a custom, transparent UIView on top of a UIScrollView. Then you can hide the default scroll bar (by using showsHorizontalScrollIndicator and showsVerticalScrollIndicator), pass the necessary touch events to the UIScrollView to scroll the content, and draw the scrollbars in your custom view.