2012-02-29 84 views
0

我創建了一個按鈕:按鈕響應UIControlEventTouchUpInside並觸及方法

button = [StretchableButton new]; 
[button addTarget:mainViewController action:@selector(addNumberFromButton:) forControlEvents:UIControlEventTouchUpInside]; 

裏面的StretchableButton I類有:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    [self.nextResponder touchesBegan:touches withEvent:event]; 
} 

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 
    [self.nextResponder touchesMoved:touches withEvent:event]; 
} 

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { 
    [self.nextResponder touchesEnded:touches withEvent:event]; 
} 

觸摸方法被調用,但button沒有的點擊反應。

任何人都可以幫助我嗎?

+0

我不知道你正在試圖讓按鈕在這裏做...你是不是想使拖動的按鈕的寬度擴大? (我猜是因爲你稱之爲可拉伸按鈕) – mdominick 2012-02-29 14:17:13

+0

對不起,我的英文。我有按鈕查看。如果觸摸按鈕並將其拉出,我想用手指移動視圖。如果我只是觸摸按鈕,我想調用方法addNumberFromButton: – Radislav 2012-02-29 14:19:34

+0

好的。由sch列出的超級事物應該工作。祝你好運。 – mdominick 2012-02-29 14:24:11

回答

1

添加手勢識別,代碼示例:

UIPanGestureRecognizer *gesturePan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)]; 
    gesturePan.maximumNumberOfTouches = 1; 
    gesturePan.minimumNumberOfTouches = 1; 
    gesturePan.delegate = self; 
    [myButton addGestureRecognizer:gesturePan]; 
    [gesturePan release]; 

....

- (void)pan:(UIPanGestureRecognizer *)gesture 
{ 
    if ((gesture.state == UIGestureRecognizerStateChanged) || 
     (gesture.state == UIGestureRecognizerStateEnded)) { 


    CGPoint location = [gesture locationInView:[gesture.view superView]]; 
//add calculation view location on it superview 
    [gesture.view superView] setCenter:newLocation]; 

}