2010-09-09 61 views
0

即時通訊面臨的問題是,在上面的部分我有滾動視圖有不同的圖像點擊它將克隆到屏幕上的相同圖像。我已啓用觸摸,所以我可以拖動它,但是當我點擊另一個圖像,它涉及到屏幕我可以拖動那個anotther圖像,但不是現在的前一個。任何人都可以有一個解決方案,所以我可以拖動多個圖像點擊它。我可以把4-5放在上面供我使用。iphone形象。多點觸摸/拖動

我有使用此代碼: 代碼:

-(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]; 
} 

在此先感謝。

回答

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