gpt4 book ai didi

iOS - UITapGesture 是否开始和结束?

转载 作者:行者123 更新时间:2023-11-29 04:33:21 26 4
gpt4 key购买 nike

问题:

我正在尝试使用UITapGestureRecognizer更改 View 的背景颜色。本质上,当用户点击时,我希望背景改变颜色,并且在释放或完成时,背景颜色返回到零,或者没有背景颜色。

此操作类似于默认的 UIButton,但我需要将其放在 View 上。

问题:

我尝试使用类似的代码:

- (void)handleTapGesture:(UITapGestureRecognizer *)recognizer
{
if(recognizer.state == UIGestureRecognizerStateBegan) {
self.backgroundColor = [UIColor greenColor];
}

if(recognizer.state == UIGestureRecognizerStateEnded) {
self.backgroundColor = nil;
}
}

没有任何成功。这是了解点击手势何时开始和结束的正确方法吗?

最佳答案

使用这些方法可能会更容易,这些方法应该已经成为 UIViewController 中响应程序链的一部分,除非它们已经在其他地方处理

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {    
//CGPoint touchPoint = [[touches anyObject] locationInView:self.view];
NSLog(@"began");
}

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
//CGPoint touchPoint = [[touches anyObject] locationInView:self.view];
NSLog(@"end");
}

关于iOS - UITapGesture 是否开始和结束?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11398403/

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