2012-11-18 75 views
0

我有兩個按鈕添加圖像和編輯。 從添加圖像我從畫廊添加多個圖像,並可以移動每個圖像視圖。 我做了一個Draggable類來移動每個imageview。如何選擇點擊或觸摸開始事件的UIImageVIew

@interface Draggable : UIImageView { 
    AppDelegate *objectDelegate; 
    CGPoint startLocation; 
} 

@property (nonatomic,retain) AppDelegate *objectDelegate; 
@end 

@implementation Draggable 
@synthesize objectDelegate; 

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { 
    // Retrieve the touch point 
    objectDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
    CGPoint pt = [[touches anyObject] locationInView:self]; 
    startLocation = pt; 
    [[self superview] bringSubviewToFront:self]; 
} 
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { 
    // Move relative to the original touch point 
    CGPoint pt = [[touches anyObject] locationInView:self]; 
    CGRect frame = [self frame]; 
    frame.origin.x += pt.x - startLocation.x; 
    frame.origin.y += pt.y - startLocation.y; 
    [self setFrame:frame]; 
} 
@end 

以及我如何添加圖像。

UIImage* image = [[UIImage alloc] init]; 
image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
CGRect cellRectangle; 
cellRectangle = CGRectMake(20 ,50,image.size.width/6 ,image.size.height/6); 

//[[self view] addSubview:blockView]; 
UIImageView *dragger = [[Draggable alloc] initWithFrame:cellRectangle]; 
[dragger setImage:image]; 
[dragger setUserInteractionEnabled:YES]; 

[self.view addSubview:dragger]; 

現在在編輯按鈕我想編輯特定的圖像b選擇單觸。像我有3張圖片picOne,picTwo和picThree。如果我觸摸picTwo並單擊編輯我想picTwo編輯(打開鳥舍編輯器)。

我做什麼這樣做,我增加了關於可拖動觸摸這條線開始

UITouch *touch = [touches anyObject]; 

    if ([touch view] == objectDelegate.selectedImageViewFromCanvas) 
    { 
     // selestecImageViewFromCanvas is UiImageView. 
     NSLog(@"dragger"); 
    } 

但這種說法是始終爲false。 我希望每個人都能得到我想要的。謝謝

+1

Zohaib請使用手勢識別碼,將工作變得非常容易。移動任何物體.. –

+0

好吧,我會嘗試吧。但不能我選擇圖像我現在工作的方式? – Zohaib

+0

確定我會嘗試肯定 – Zohaib

回答

0

謝謝Arpit。我已經使用手勢識別器link。我已編輯此代碼。在imagepicker我有UiView(holderview)和UIImageView(imageview)設置標籤,當我點擊圖像,然後我可以得到標記值的持有人[發送者視圖]。標籤。並從該標籤我得到的是UIImageView的標籤,例如[發送者視圖] .TAG + 1(表兄弟姐妹,如果我的holderView標籤是101比我的UIImage標籤是102)