iPhone - scrolling a UISCrollview to keep objects moving - iphone

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.

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.

UIScrollView w/ zoom doesn't scroll until zoomed

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"

In iphone, how to select desired size image from an image

Like in MS paint when we want to select portion of image we select rectangular box & drag over the image by click & holding left mouse key till the desired location.
How can we do the same functionality in iphone.
Plz help....
You can use multitouch in an image view and touch two points to mark the corners of the selection rectangle. You can then drag both fingers around to change the selection rectangle, and lock the selection when you lift one or both fingers.
Another alternative is to put the image in a scrollview. Then zoom and pan the subview around inside the scrollview until the portion that just fits the full scrollview represents the selection. You can put the control buttons outside the scrollview, or have them fade out and fade back in after some amount of time after the user has stopped moving the selection around.

Understanding UIScrollView

I'm trying to understand how UIScrollView works for zooming.
I was trying to rotate a UIImageView within a zoomed UIScrollView and I ended up with weird sizes, my centering in the scrollview not working anymore.
I solved the problem by setting the zoomScale to 1.0 before doing the rotation, and then by resetting it back to the previous value once the transformation was done.
I was wondering what was the impact of the UIScrollView on its subviews. Does it change their sizes, their positions. Or is it simply the UIScrollView that handles the zooming and the drawing of the zoomed subviews.
I realise that is an old question, but I thought I'd add additional information for those still arriving here like myself.
The scroll view manages its contents view, it zooms by adding tranformations to the content. So, for an image when you zoom in, it uses a tranformation to scale the image to the required zoom level.
When you are panning/scrolling a ScrollView, it changes the zoom level and origin positions to move the content around. So the content may well be larger than the scrollview itself. It clips the content at the scrollviews bounds and just adjusts this origin position.
The central notion of a UIScrollView object (or, simply, a scroll view) is that it is a view whose origin is adjustable over the content view. It clips the content to its frame, which generally (but not necessarily) coincides with that of the application’s main window. A scroll view tracks the movements of fingers and adjusts the origin accordingly. The view that is showing its content “through” the scroll view draws that portion of itself based on the new origin, which is pinned to an offset in the content view. The scroll view itself does no drawing except for displaying vertical and horizontal scroll indicators. The scroll view must know the size of the content view so it knows when to stop scrolling; by default, it “bounces” back when scrolling exceeds the bounds of the content.
Source Documentation

Rotating UIWebView with transform, content partially off screen, how to get it to stick on screen?

I have a 320x416 portrait-shaped UIWebView filling a UIViewController's view. I also have a 90 degree rotate button that will transform the UIWebView through 90 degrees each time the button is touched. The code is basically:
webView.transform = CGAffineTransformMakeRotation(touches%4 * M_PI/2.0);
After rotation through 90 degrees, the now-landscape transformed UIWebView extends beyond both the left and right edges of the screen. In the process of applying the transformation, iPhone OS has changed the UIWebView's frame from {{0,0}, {320,416}} to {{-48,48}, {416,320}}. Don't have a problem with that.
I then tweak the UIWebView's frame origin to (0,0) so that it starts top-left, but extends a little further beyond the right edge of the screen. Now, I can touch the UIWebView and pull it left to view the hidden information on the right but I cannot get the right-hand end to to stay on the screen -- the moment I untouch it, the right side bounces back off the screen.
What is it that causes the view to bounce back off-screen? In other words, what is it that I need to tweak to allow either the left edge or the right edge to stick on the screen and remain visible (only one at a time, obviously)?
Thanks.
As far as I understand what you've done in your project, what you are seeing is the normal behaviour of any scrolling window in iPhoneOS. That is, your UIWebView is wide enough to contain all the HTML content displayed within so while it will move when you drag it, it springs back to its original position when you let go. The fact that the UIWebView is wider than the screen due to the fact that you've rotated it, but not resized it, means that you can't see it all the HTML content, but as far as the UIWebView is concerned it's all visible so it doesn't let you properly scroll it, it just bounces.