我面临的问题是,在上面的部分我有滚动视图,它有不同的图像点击它会将同一图像克隆到屏幕上。我已启用触摸,所以我可以拖动它,但当我点击另一个图像,它来到屏幕,我可以拖动其他图像,但现在不是前一个。任何人都可以有一个解决方案,所以我可以点击它拖动多个图像。我可以把4-5放在上面供我使用。
我使用此代码: 代码:
-(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];
}
提前谢谢。
答案 0 :(得分:1)
我很难确切地说出问题所在,但我怀疑你可能会对你正在听的事件感到困惑。这样的东西可以让你告诉点击什么图像然后在它上面执行拖动操作。
#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