I crawled all the web, but nothing.
I have a for loop to create uiimageview inside a uiscrollview controller. It's a collection of images that you can scroll horizontally only.
for (int i = 0; i < NIMAGES; i++) {
NSString *filename = [NSString stringWithFormat:@"image%d.png", i+1];
ScrollerImage *iv = [[ScrollerImage alloc] initWithNibName:@"ScrollerImage" bundle:nil];
[iv initWithImage:[UIImage imageNamed:filename]];
iv.frame = CGRectMake(i * 320.0f, 0.0f, 320.0f, 150.0f);
iv.exclusiveTouch = YES;
iv.userInteractionEnabled = YES;
[sv addSubview:iv];
[iv release];
}
The ScrollerImage class is an UIImageView controller
#import <UIKit/UIKit.h>
@interface ScrollerImage : UIImageView {
}
@end
Now, how can I drag (not necessary a move, also a copy of view, or an id of view, anything that permit me to identify the image) an image from the scroller to another view? It's like a shopping cart, where you can drag items at the bottom view (cart).
Like this:
This is an alternative, using
UIGraphicsGetImageFromCurrentImageContext()
You can grab an image from currentScreen on click or after some events. Next renderize it to screen and apply a Pan gesture to move around the screen.
sample code:
--- EDIT ---
A sample project on github: https://github.com/elpsk/Shopping-Cart
I've been trying to implement this in an app of mine and I had to just give up. I subclassed
UIImageview
like you have as well(which is a good option) and all my images are on a UIView that is a subclass ofUIScrollView
. You can pass your viewcontroller to the images themselves and change which view the imageview is a subview to when it reaches a certain boundary (I overrided thetouchesMoved
on theImageViews
themselves). The problem with this is it doesn't drag continously. The user has to literally select the image again when they dragged the image across a certain point because you're literally switching the uiimageview from one view to another.I hope this gives you some insight at least, I really haven't found a solution to this issue. You'd think a lot of IPad apps would be paving the way to drag images all over different views and more tutorials appear on the issue!