UIScrollView w/ zoom doesn't scroll until zoomed - iphone

I have a UIScrollView loaded with a UIImageView, so that the user can zoom in, and then scroll if necessary. However, if the image is larger than the screen, scrolling doesn't do anything until the user pinches to zoom (even just one pixel). For example, the image might be 320 x 600, so they see a section 320 x 480, but would have to scroll to see the rest. However, the scrolling wouldn't work until they zoomed in or out. Is there any way to avoid this?

Have you called -setContentSize: on the scroll view? If you haven't, it won't know that there is offscreen content to display.

Was stuck on this problem for almost a whole day. In the far right window, click on the far left button like so
Then uncheck the "Use Autolayout"

Related

iPhone - scrolling a UISCrollview to keep objects moving

I have a UISCrollview. Inside this scroller I have a picture and over the picture I have some objects (as subviews of the picture), like layers in a Photoshop composition. So, if I zoom the picture, the objects will zoom. If I scroll the picture, the objects scroll.
Now consider this: I have the picture zoomed in. The picture is now larger than the iPad screen. I am seeing the top half of the picture. I touch an object that is over the picture and start dragging it to the bottom of the screen. My intent is to drop the dragged object at the bottom of the picture, but as the picture is zoomed in, I have to drag the element to bottom of the screen, release it, scroll the picture up and then continue dragging the object.
What I want is this: I start dragging and when I arrive at the boundary of the screen, the scroller starts scrolling automatically showing parts of the image that were down or up.
What do I need is to know the rect that is visible, a kind of inverse of scrollRectToVisible...
Considering that the picture can be zoomed at any level, how do I know if the element I am dragging is near the border. BTW, how do I know what part of the scroller is being shown, even if it is zoomed?
thanks.
The visible rectangle has a size of scrollView.bounds.size and an origin of scrollView.contentOffset, in the coordinate space of the scrollview. Depending on what exactly you are doing, you may need to use convertRect:fromView: or convertRect:toView: to convert it into the coordinate space of the zoomed view.

Touches on the center, image moves to the right while start zooming in a UIScrollView

I am implementing a scrollview based on the code of Scrolling Madness found on git and I update it for an infinite image scrolling like a magazzine using three uiimageviews:
- 1st uiimageview: last page
- 2nd uiimageview: first page
- 3rd uiimageview: second page
The code uses the scrollRectToVisible to center in the screen the second uiimageview but when I start zooming it with the fingers on the center, the image moves to the right, leaving a part on screen and the left size on blank. The zoom works fine and everything but the behavior of the image isn't the correct.
I checked the Scrolling Madness project and I replicated the same behavior. The second image moves to the right, and the third one goes off screen.
Any ideas of how to correct this? I have tried to modify the contentoffset and other options of the scrollview but no success.
I found another solution that worked for me after seeing another zoom project on the web. In the Scrolling Madness project, in the setZoomingMode function, set your scrollview's content size the same as your uiview that will be zoomed. Also, in my case, I modified the uiview's frame's origin to make it visible on the screen.
I found a very useful method that solved the problem on this page: http://idevzilla.com/2010/10/04/uiscrollview-and-zoom/

trouble with rotating view (and resizing elements within) in ipad application

I'm having a nightmare with the rotation on iPad. I've searched all over the place for some tutorials, but nothing seems to really be for what I want. (Possibly not searching for the right thing?!)
I have a portrait view by default which is an image and a button inside the view. When I rotate, I detect this can work out if it's landscape. I then try to set the frame size of the uiview to fit nicely on the screen.
If I let it autoresize, it simply stretches and fills the screen. This I don't want.
but the trouble is, when I resize, the button gets resized too, but not in the same ratio as the image.
My question is: What's the best way to resize the view. I wanted to simply reduce the uiview by say 60% and it resizes EVERYTHING in that view with the same 60%. The only way I see this is working at the moment is to create two views... but that's twice the work and maintenance!
I've tried messing with the autosizing arrows in Interface builder, but that again seems to screw things up more!
I'm completely lost here!! Thanks for any info
The problem you have there is that the view is automatically resized to the screen ratio. On an iPad in Portrait Orientation the screen size is 1024x768. After the rotation to Landscape the origin rotates too and your screen content is skewed or stretched to 768x1024.
What you need to do is to override the
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
message of the UIViewController of the view which rotates. This message is called within the animation block of the rotation. You just set the framesize of your subviews (the button) to whatever is best for you. Once i had a problem with rotating an OpenGL view. The content of the view was stretched when rotating to landscape. Since it is not possible to alter any OpenGL matrices within the animation block the only solution i found was to make the view quadratic and to set the origin behind the bounds of the screen (in -x direction). You have to override the message also to reset the origin above the screen (in -y direction) bounds in landscape mode, to keep the viewport in the middle of the screen. That way the view kept its ratio. Whatever solution is best for you, overriding this message should work out.
Have you tried disabling the autoresizesSubviews property on your UIView? It should prevent any size changes on the subviews when you resize your view.

How to dynamically restore the UIScrollView's zoom level and position when my app relaunches?

My application consists of a UIImageView inside a UIScrollView, and I display a big image inside of it. The scroll view allows the user to pinch to zoom in/out in the image, and that all seems to work just fine.
However, when my application is terminated and then re-launched, the UIScrollView displays the image again in the original zoom level (which is currently set to display the whole image, by scaling it in a "aspect fit" mode).
I would really like to be able to re-launch my app and have the UIScrollView reopen with the same parameters as it was set when the app terminated. So if my image is currently zoomed in to the max, and scrolled all the way to the bottom left of it, that should be the view when I open the app again.
How can I do this?
Check the .transform property of the view. If you are zoomed in, this should be modified. Save and restore it on the next launch.
I have found a way to programmatically zoom UIScrollView. This may help you set the desired zoom level upon startup.
The sample code, together with ZoomScrollView class that encapsulates the required zooming magic and a detailed discussion of how (and why) UIScrollView zooming works is available at github.com/andreyvit/ScrollingMadness/.
Someone asked this a while ago, but I don't think you'll like the answer. Hopefully you'll get a better one.
I do it like this:
When you quit save the zoomlevel (myScrollview.zoomScale) and the contentview frame origin.
When you reopen you can set the zoomscale. You also have to set the content size to the new zoomlevel, because otherwise the boundaries are not correct.
[myScrollview setZoomScale:savedZoomScale];
CGSize newsize = CGSizeMake(origsize.width * savedZoomScale,
origsize.height * savedZoomScale);
myScrollview.contentSize = newsize;
To set the offset:
[myScrollView setContentOffset:savedFrameOrigin animated:YES];

iPhone SDK: disabling cllipping for UIScrollView

I'm working on an iPhone game, and trying to use a UIScrollView to display some icons, which I then want to enable the user to drag off the bar being scrolled, onto another view (basically, dragging them from their hand into play on the game board). The problem is that the UIScrollView clips everything outside it's own bounds.
Here is a picture of what I'm trying to do:
Functionally, it actually works, in that you can drag the icons up to the white board fine...but you can't see them as you are dragging...which is not acceptable.
Does anyone know if you can temporarily disable the clipping that a scroll view does, or is there some way to get around it? Hacky or not, I would really like to make it happen.
Does anyone have any other possible solutions for this? Or maybe any alternate approaches? I've considered if maybe a page view might work, but haven't tried it yet...and it's not at all as good of a solution as the scroll view.
Worst case I can just go back to not having the bar scrollable, but that really puts a damper on some of my game mechanics, and I'm really not too excited about that.
I think you're looking for the clipsToBounds property of UIView. I've used it successfully with UIScrollView:
scrollView.clipsToBounds = NO;
However, the dragging you want to do from the scroll view to the game view may require you to remove the icon view from the scroll view, place it in the superview at a position corresponding to its visible position within the scroll view (calculated using the scroll view's origin and content offset), and have that track the user's finger movements. On a release of the touch, either drop it on the game view at the proper position or return it to the scroll view.
I'm not 100% sure I understand the question but I think you should look into the z order of the scrollview and the whiteboard. It may be that the drag is just going behind the whiteboard.
Failing that, it would be useful to see all the bounds of your view heirarchy.
I also think a better solution allround might be to create a "sprite" to animate underneath the players finger - you could offset the drawpoint of the sprite from the touchlocation so that the player can see what they are dragging.