2012-02-03 3 views
0

私はそれを押すと、私が追加したターゲットセレクターを起動しないボタンがあります。私はボタンの異なるイメージを作ったので、私はそれを押すことがわかります。外部にドラッグしない限り、UIButtonはtouchUpInside上のターゲットを発射しませんか?

私はここをクリックし、ボタンの外側にドラッグしますが、ボタンのすぐ上のスーパービューの外にはドラッグしないでください。ターゲットセレクタが起動されます。

私はまた、すべてのスーパー/サブビューでsetClipsToBounds:YESを設定して、それがビューの境界内にあることを確認しました。境界内にあるようだ。ボタン領域の外にドラッグすると無指向であるように見えるので、右にタップ/ドラッグするだけのことはできません。左と右の仕事も残してください。私はタップすることができます、それからドラッグして戻って、それは動作します。ドラッグを開始せずにタップしたままにすると、ボタンがハイライト表示されてから非選択状態に戻ります。

ボタンのコードは次のとおりです。ボタンはUITextView、実際には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]; 

あるこのすべてであるが、拡大表示であることをUIViewのは、スクロールビューは、その上にいくつかのジェスチャー認識機能を持っています。彼らは私がスクリーンに置いた他のボタンやコントロールを妨害しているようには見えませんが。私はそのスクロールビューが問題であると感じていますが。

スクロールビューのコードクリップ:

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