Reputation: 1369
The problem im facing rightnow is that in an above portion i have scrollview which have different images clicking on it will clone a same image on to the screen. i have enable touches so i can drag it, but when i clicked another image and it comes to the screen i can drag that anotther image but not the previous one now. can any one have a solution so i can drag multiple images on clicking on it. i can put 4-5 on it for my use.
i have use this code: Code:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[[event allTouches]anyObject];
CGPoint location = [touch locationInView:touch.view];
g1.center = location;
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
[self touchesBegan:touches withEvent:event];
}
thanks in advance.
Upvotes: 0
Views: 283
Reputation: 6983
It's hard for me to tell exactly what the problem is, but I suspect you might be getting confused on what events you are listening too. Something like this will enable you to tell what image is being clicked on and then preform the drag actions on it.
#import "TouchView.h"
//TouchView.h
#import <Foundation/Foundation.h>
#import "TouchViewDelegate.h"
@interface TouchView : UIView {
id <TouchViewDelegate> delegate;
}
@property (retain) id delegate;
@end
//TouchView.m
@implementation TouchView
@synthesize delegate;
-(id) initWithFrame:(CGRect)frame
{
self.userInteractionEnabled = YES;
return self;
}
-(id) initWithCoder:(NSCoder *)aDecoder
{
self.userInteractionEnabled = YES;
return self;
}
-(void) awakeFromNib
{
self.userInteractionEnabled = YES;
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[delegate touchDown:self];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[delegate touchUp:self];
}
@end
//TouchViewDelegate.h
#import <UIKit/UIKit.h>
@protocol TouchViewDelegate
-(void) touchDown:(id) sender;
-(void) touchUp:(id)sender;
@end
Upvotes: 1