gpt4 book ai didi

objective-c - 响应 UIControlEventTouchUpInside 和触摸方法的按钮

转载 作者:行者123 更新时间:2023-11-29 04:46:55 25 4
gpt4 key购买 nike

我创建了一个按钮:

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

调用触摸方法,但按钮对点击没有反应。

有人可以帮我吗?

最佳答案

添加手势识别器,代码示例:

    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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com