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!
Related
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
resizing images inside UIScrollView when rotating the iphone.
I have a series of images placed on the UIScrollView (some images are placed one on top of the other). When I rotate the scrollview at some page, the topmost image on the hierarchy is expected to rotate which happens but the image goes to the first page of the scrollView. Any help on what could be going wrong would be appreciated.
thanks
DKV
I think the imageView which is misbehaving w.r.t to its frame is not added into correct super view. I think you should check that all imageView are added onto scrollView (if you want to show one imageView above another imageView make frame of both the imageView same, avoid adding one imageView onto another imageView).
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
When you tap the bookmark, it slides down or up smoothly. As it slides up, it disappears as if behind the view directly above it. I know how to animate changing the frame of a view, but I don't know how to make it disappear like that. (I don't want to resize the UIImage, just slide the UIImageView up and out of sight.)
I figure I need an invisible button to toggle the animation, and an UIImageView to animate. Do I need to change the bounds of the UIImageView, or should I use the frame? I thought I could just change the height from X to 0, but it didn't seem to resize the UIImageView. I had a little luck with settings the bounds with clipping subview's enabled, but I wasn't quite there.
I don't think I understand the relationship between the bounds and the frame.
I ended up adding a parent UIView to contain the UIImageView. It has the dimensions in which I want the UIImageView to be viewable in, and then I just animate the frame so the Y dimension is equal to the negative height and it slides up nicely.
I was on the wrong track with the bounds.
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.