2011-05-20 47 views
0

嗨朋友我創建了這種方法的圖像選擇它正常工作,但我面臨着圖像上的問題,當我觸摸圖像我不能看到圖像點擊或不是我想突出圖像時我觸摸它我怎麼能做到這一點如何在iphone上觸摸事件突出顯示圖像

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location= [touch locationInView:self.view]; 
    if(CGRectContainsPoint(firstImage.frame, location)) 
    { 
     // flag like 
     select=1;   
    } 
    else if(CGRectContainsPoint(secImage.frame, location)) 
    { 
     select=2;   
    } 
    [mComment resignFirstResponder]; 

} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:self.view]; 

    if(CGRectContainsPoint(firstImage.frame, location)) { 
     if(select==1) { 

      var=1; 
     }} 
    else if(CGRectContainsPoint(secImage.frame, location)) { 

     if(select==2) { 
      vars=1; 
     }} 
    select=0; 
} 
+0

你有兩個圖像(一個用於正常狀態,另一個用於高亮狀態)?最好有兩個圖像。在touchDown中的imageView中設置突出顯示的圖像,並在touchUp上重新設置普通圖像。 – EmptyStack 2011-05-20 07:21:58

回答

1

你可以做一件事,當你觸摸它時突出圖像。當你觸摸圖像時,你應該改變觸摸開始方法中所選圖像的alpha,並在觸摸結束方法中重置圖像alpha。所以它看起來像按鈕。

對於防爆。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ 
    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location= [touch locationInView:self.view]; 
    if(CGRectContainsPoint(firstImage.frame, location)) 
    { 
     // flag like 
     select=1;   
     firstImage.alpha = 0.5; 
    } 
    else if(CGRectContainsPoint(secImage.frame, location)) 
    { 
     select=2;   
     secImage.alpha = 0.5; 
    } 
    [mComment resignFirstResponder]; 

} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 

    UITouch *touch = [[event allTouches] anyObject]; 
    CGPoint location = [touch locationInView:self.view]; 

    if(CGRectContainsPoint(firstImage.frame, location)) { 
     if(select==1) { 
      firstImage.alpha = 1.0; 
      var=1; 
     }} 
    else if(CGRectContainsPoint(secImage.frame, location)) { 

     if(select==2) { 
      secImage.alpha = 1.0; 
      vars=1; 
     }} 
    select=0; 
} 
+0

它是如何工作的朋友可以提供樣品 – Rani 2011-05-20 07:12:54

+0

嗨Rani,我已經更新了我的ans使用你的代碼嘗試它。 – 2011-05-20 07:17:23

+0

嗨拉尼,它的工作與否? – 2011-05-20 07:22:59