2012-02-27 94 views
0

我有一個視圖具有響應拖動事件的UIButton。這一切都正常工作,問題是該按鈕只有70X70,拖動時用於手指的按鈕圖像大部分被手指遮住(該過程是用戶拖動圖像(UIButton)到視圖上的目標區域) 。有沒有辦法來抵消拖動手柄,所以它不是UIButton的中心點?理想情況下,我希望它是UIbutton圖像的右上角,因爲左下角是我最關心用戶看到的區域。在拖動UIButton時移動拖動手柄

編輯:這是我用來處理觸摸(拖拽)事件的代碼:

- (IBAction) imageTouch:(id) sender withEvent:(UIEvent *) event 
{ 
    UIButton *thisButton = (UIButton *)sender; 

    CGPoint centerPoint = [[[event allTouches] anyObject] locationInView:self.view]; 
    UIControl *control = sender; 
    control.center = centerPoint; 

    UIColor *selColor = [WebImageOperations getColorFromImage:self.targetImageView.image atX:point.x andY:point.y]; 

    NSInteger thisScore = [Scoring scoreFromUIColor:selColor withArrow:thisButton.tag]; 

    switch (thisButton.tag) { 
     case 10: 
      arrow10Score = thisScore; 
      self.score10Label.text = [NSString stringWithFormat:@"%d", arrow10Score]; 
      break; 
     case 12: 
      arrow12Score = thisScore; 
      self.score12Label.text = [NSString stringWithFormat:@"%d", arrow12Score]; 
      break; 
     case 14: 
      arrow14Score = thisScore; 
      self.score14Label.text = [NSString stringWithFormat:@"%d", arrow14Score]; 
      break; 

     default: 
      break; 
    } 

    NSInteger totalScore = arrow10Score + arrow12Score + arrow14Score; 
    self.totalScoreLabel.text = [NSString stringWithFormat:@"%d", totalScore]; 
} 
+0

給我們一些代碼。 – Melvin 2012-02-27 22:22:06

+0

有你去。添加代碼 – 2012-02-28 10:29:44

+0

可能是https://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIButton_Class/UIButton/UIButton.html#//apple_ref/occ/instp/UIButton/contentEdgeInsets或https:// developer .apple.com/library/ios /#DOCUMENTATION/UIKit/Reference/UIButton_Class/UIButton/UIButton.html#// apple_ref/occ/instp/UIButton/imageEdgeInsets – Melvin 2012-02-28 11:32:31

回答

0

我不認爲這是可能的。如果有人遇到此問題並提供解決方案,請將其發佈到此處,並將該答案標記爲正確答案。