How can we drag and drop image inside scrollview - iphone

In my application am having CustomScrollView subclass of UIScrollView (I am not using UIView here) in which I have 10 images at bottom and I want to drag any image from bottom to anywhere in scrollview by making copy of it and not deleting original at bottom. BY using touchEnd , touchMoved and touchBegan functions

in your touch begin method you will get touch points and will be able to get imageView where touch begin. Now if you want to show moving of image view do following:
in touch begin get the UIImageView object
create a new UIImageView object with same properties.
UIImageView *newImageView = [[UIImageView alloc] initWithFrame:myCurrentImageView.frame];
newImageView.image = myCurrentImageView.image;
//other properties if needed
[myscrlview addSubView:newImageView];
This will add image in your scroll view at same place your previous image view was.
In touch move you will get your touch points
set your any of UIImageView object lets say
newImageView.center = touchPoint;
this will show your image moving
In thouchEnd do the same set your newImageView center at touch end position.
Make sure that you set your UIScrollView properties like content size and every thing as well while moving new image may have origin negative in case your center set to x=0, y=0.
This will keep the previous image as it is in scroll view and create a copy of new that image while moving.
Hope this is what you looking for. If not let me know.
Note: Code may have errors as I just typed here not in xcode but you can understand what to do

Related

iPhone - How to partially hide the subview?

I am developing one sample application using gestures, where i can pinch, pan and rotate. I have one main image view width and height is 300 and origin x is 0 and y is 70. This imageview I am using from interface builder. After this i am adding one label programmatically on the middle of the imageView. After adding the label I can able to pan, pinch and rotate the label on the view. Now the actual requirement is when i drag the label outside the imageview I should be display the partial label, for example (My label text is ABCDXYZ). As soon as I drag the Z outside the Z should be invisible, other part ABCDXY should be visible. More clear is drag the one view inside other view. How can i achieve this.
What you have to do is create a UIView. On that add the UIImageView like
[View addSubView:ImageView];
then add the UIlabel on the UIImageView like
[ImageView addSubView:Label];
Now set the clipsToBounds = YES. I think now your issue of the partial label would be solved as the label would move within the UIView and as soon as it goes out it would be shown partially. Any doubt please tell . Thanx :)
Its really tricky to give handheld solution for this, instead it could be a suggestion. I assuming that your UILabel text is dynamic, there's some scenarios you can follow to achieve this.
1) When you touch your label inside UIImageView you shoud get the exact coordinates of it.
2) Get the position where user touch on UILabel.
3) Compare the touch coordinates with total coordinates of UILabel.
4) Assume which character did touched. (You should make test of it, also text size may also matters).
5) When user drag that particular character (say Z) you need to remove that from UILabel text.
That's all. You're done.

User Interaction Enable in a UIImageView under another UIImage View

I have two UIImageView in a UIView in my application. And I need to Zoom, Rotate and Move the UIImageView which is at bottom of the top one, I don't need to do any thing with top one. I've already implemented the code for Move, Rotate and Zoom but the problem is I cant enable the touch to UIImageview in bottom.
How to solve this problem?
UIImageView's have userInteractionEnabled set to NO by default. You have to explicitly set this to YES for the image view you want to allow touch events to occur on.

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

How to add bookmark in iPhone application?

I have large image which is placed in UIImage with in the UIScrollView. I want to put Bookmark any particular point of image. How it is possible?
My App Structure
ScrollView
-ImageView
-TestImage.png
Thank you.
A couple of approaches:
1) Composite the bookmark image directly onto your UIImage and update your UIImageView in your scroll view.
2) Add an overlay of your image as a view on top of the UIImageView. This is probably easist approach. In this approach, just get the touches point and create a new UIImageView containing the bookmark and addSubview it in the touches center point (or workout if the image is a pin, where the bottom of the pin should hit on the image).

rotation of images in UIScrollView

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