我创建了一个按钮:
button = [StretchableButton new];
[button addTarget:mainViewController action:@selector(addNumberFromButton:) forControlEvents:UIControlEventTouchUpInside];
在
StretchableButton
类中,我具有:- (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
不会对单击做出反应。有谁能够帮助我?
最佳答案
添加手势识别器,代码示例:
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];
}
关于objective-c - 响应UIControlEventTouchUpInside并触摸方法的按钮,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9500566/