我创建了一个按钮:
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
不会对点击做出反应。
有人能帮助我吗?
答案 0 :(得分: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];
}