2012-02-03 29 views
0

我有一個按鈕,當我按下它時,它不會觸發我添加的目標選擇器。我製作了不同的圖片按鈕,所以我可以看到我在按下它。除非我在外面拖動,否則UIButton不會在touchUpInside上觸發目標?

所以這裏是滑稽如果我按下,並拖出按鈕的外部,但不是在按鈕的直接superView之外,目標選擇器被激發!

我也在測試中設置setClipsToBounds:YES在所有超級/子視圖上,以確保它仍然在視圖邊界中。似乎處於界限之內。在按鈕區域外拖動似乎是全方位的,所以它不像我只能點擊/拖動右邊。也上下工作。我可以點擊,然後拖出來,然後運行。如果我沒有開始拖動,只需輕按並按住,該按鈕將突出顯示,然後返回到未選中狀態。

這裏是按鈕的代碼。該按鈕與UITextView一起位於UIView上,實際上是UITextView的onTop。 UIView的,所有這一切是在上大圖,這是一個縮放/滾動視圖

 messageLookupButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 21, 20)]; 
     [messageLookupButton setTitle:@"junk" forState:UIControlStateNormal]; 
     [messageLookupButton sizeToFit]; 
     [messageLookupButton setTag:kGearButtonView]; 

      //Get the images for the buttons 
     UIImage *gearButtonImage = [UIImage imageNamed:@"gear.png"]; 
     UIImage *gearButtonImage2 = [UIImage imageNamed:@"StatusLightOn.png"]; 

     [messageLookupButton setImage:gearButtonImage forState:UIControlStateNormal]; 
     [messageLookupButton setImage:gearButtonImage2 forState:UIControlStateHighlighted]; 
     [messageLookupButton addTarget:self action:@selector(gearPressed:) forControlEvents:UIControlEventTouchUpInside]; 

     [[NSNotificationCenter defaultCenter] addObserver:self 
               selector:@selector(processLookupResults:) 
                name:kRefreshFromPopover object:nil]; 
     [self addSubview: messageLookupButton ]; 
     [messageLookupButton release]; 

     [messageLookupButton setCenter:CGPointMake(CGRectGetMaxX(elementViewContents.bounds) -kElementContentFrameOffset -(CGRectGetWidth(messageLookupButton.bounds)/2), CGRectGetMidY(elementViewContents.bounds))]; 


     [self bringSubviewToFront:messageLookupButton]; 

滾動視圖上有幾個手勢識別。儘管它們似乎不會干擾我放在屏幕上的其他按鈕和控件。雖然我感覺它的滾動視圖是問題所在。

滾動視圖代碼片段:

[scrollContentView setUserInteractionEnabled:YES]; 
[scrollContentView setExclusiveTouch:YES]; 
[scrollContentView setCanCancelContentTouches:YES]; 
[scrollContentView setDelaysContentTouches:YES]; 

回答

0

我結束了剛添加齒輪作爲圖像視圖,則創建了一個不可見按鈕,這是尺寸與我放置在齒輪圖示了UIView相同。

-(void) addMessageLookupSelector { 
     // Set a default Color if there is none 
    if (_isMessageLookupField){ 
      // Add Gear to End Of Text Field 
     if (!messageLookupImageView) { 
      messageLookupImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 21, 20)]; 
      [messageLookupImageView setTag:kGearButtonView]; 
      [messageLookupImageView setImage:[UIImage imageNamed:@"gear.png"] ]; 

      [self addSubview: messageLookupImageView ]; 
      [messageLookupImageView release]; 
     } 
     [self positionMessageLookupImageView ];  
    } 
    [self setNeedsDisplay]; 
} 



    - (void)makeControlEditable { 

      //Setup the TextField so we can edit its value, need to see if there is a Write Animation Assocated with Element 
     [self setTheWriteTag]; 
     if (writeTag) { 
      writeInputRequestedButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
      [writeInputRequestedButton setFrame:elementViewContents.frame]; 
      [writeInputRequestedButton setUserInteractionEnabled:YES]; 
      [writeInputRequestedButton setEnabled:YES]; 
       // [writeInputRequestedButton setBackgroundColor:[UIColor clearColor]]; 
      [self addSubview: writeInputRequestedButton]; 
      [self bringSubviewToFront:writeInputRequestedButton]; 
      [writeInputRequestedButton addTarget:self action:@selector(wantsToEditValue:) forControlEvents:UIControlEventTouchUpInside]; 
     } 
    } 
相關問題