rotation of images in UIScrollView - iphone

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).

Related

Resizing a UIView containing UIButtons makes those buttons lose perspective position

I got a UIView that contains an UIIMageView and several buttons that are allocated on certain position related to the image of the UIIMageView.
The frame of the UIView is (0,0,250,250)
the UIIMageView that is within the UIView is set to autorisizing (all) in IB.
All buttons are set to autoresize (none) and origin middle.
When i change the frame of the UIView i.e (0,0,500,500) the UIIMageView (and image) resize OK but the buttons lose their perspective position by a few pixels (about 2 to 3 in the vertical and horizontal axis).
Is this normal? can someone advise?
Try putting the buttons inside another UIView and then setting the autoresizing options on this new view. You should leave the buttons without autoresizing inside the new view.
there is no answer after all.
I must accept the fact that the resized view and the buttons within it will lose perspective position by 2/ 3 pixels off the x/y axis...
strange....

Display UIImageView image over it's parent UIImageView

I have an easy task but still don't get how to make it work.
I have a UIView, inside the UIView i have the main UIImageView of half UIView size (half display).
And inside of the UIImageView i have two UIImageViews with images.
I need to pan the internal UIImageViews, and that's not a problem but the problem is that it will not go above the parent UIImageView borders. Same happens when i use two UIImage instead of UIImageView.
I have tried to bring it on top (bringSubviewToFront) but it does not help because its parent controller not the UIView. And the two internal UIImageViews must be a part of the main UIImageView because the main UIImageView can move, so i move all together.
Any help appreciated.
Although the correct solution is to have a superview that's the correct size, you can always "see" what lies outside of the bounds by setting clipsToBounds to NO on the parent UIImageView.
This will draw the subviews even if they lie outside the bounds of the superview. Keep in mind though, that the parts that are outside the bounds will not react to touches, i.e the hit box is always clipped.
You can have one parent view, containing large image and two smaller as siblings. Then you an control position of two images freely without attaching them to larger image.
Like this:
-Parent View (the largest, within which all images aare displayed)
- Large image
- small image
- small image
Now small images are free, and you can align them to large image whenever you want!

how to drag an uiimage from scrollview to another uiimageview in iphone sdk

In My Application,i am having one scrollVIew containing multiple images.
and out of the scrollview i have one uiimageview.
i want to Drag any image from ScrollView and drop it on uiimageview which is out of the scrollview.
is it possible?
help And suggestions are appreciated
Thanks in advance.
gamozzii's reply is close to what you need to do, but there's one problem. An UIScrollView will eat touches, so tapping on an image will have no effect.
As a result you will have to subclass the UIScrollView
I have written a small functional app to illustrate dragging the image from a scroll view into an image view. You can download the project here.
Yes this should be possible, you will need to implement the touch/drag events directly.
Check out the touchesBegan, touchesMoved etc. delegate methods in UIResponder.
One approach would be to subclass imageview and implement touchesBegan, touchesMoved in it, and use this imageview subclass to display your images in the scroll view.
On the touchesBegan create a new image view and add it to the outer view and set its image to be the same as the one in the scroll view. You need to overlay it directly over your source image in the scroll view so adjust its frame origin to be relative to the outer view you will need to use the scrollview origin and also the content view size and offset of the source image view inside the content view in order to recalculate the new origin in the outer view.
Then on the touches moved, simply readjust the frame of this image in accordance with the coordinates from the touches moved so that the image follows the touch.
Do a boundary check against the frame of your target imageview - once the user drags it into this boundary, make that target imageviews image the same as the image in the view being dragged and remove the dragged image from the containing view and release it.
In case you're still interested in another solution (and for other users of course):
I did implement that behaviour before just like gamozzii recommended.
I set canCancelContentTouches = NO on the UIScrollView to make sure the subviews handle there touches on their own. If a subview (in your case an image) was touched, i moved the view out of the scrollview onto the superview and started tracking it's dragging. (You have to calculate the correct coordinates within the new superview, so it stays in place). After dragging finishes, i checked if the target area was reached, otherwise I moved it back into the scrollview.
The subviews are handling the dragging on there own via (touchesBegan:/Moved:/Ended:/Cancelled:).
If that's not detailed enough, here's my example code: Github: JDDroppableView

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 - strange issue with UIScrollView and touches

I have two UIImageView objects inside my view (both 320x480 one above the other). The lower image view is inside a UIScrollView with scrolling and zooming enabled. Now I want to handle touches inside the other image view but it no longer detects any single taps.
I can understand that the UIScrollView handles all the touches which I do on it. But the touches on the image view above the scroll view are also not recognized.
Attached is an image with my view hierarchy. Can someone please tell me why the other image view's touches are also handled by the scrollview when it isn't a subview of scroll view?
And if the scrollview is bent on handling touches, how do I recognize touches on the other image view?
Thanks.
By default UIImageViews have userInteractionEnabled=NO;
Try setting it to YES (either in IB or in code).
I'm not sure, it might be that you need to set the frame size and/or content size of the scroll view properly. This page has a diagram of what I'm talking about.