Bri*_*ian 6 uigesturerecognizer ios
这可能已在某处发布,但我找不到它.我正在编写一个带有两个UIViews的简单iOS应用程序.用户将首先按住屏幕的某个区域,然后释放它们的触摸,然后快速触摸下面的第二个视图.
第一个UIView附加了一个UILongPressGestureRecognizer,工作正常.第二个UIView附加了一个UITapGestureRecognizer,也可以正常工作.但是,我不能让这些手势识别器中的任何一个返回任何声明用户释放其触摸的内容.
我试过这段代码无济于事:
- (void)holdAction:(UILongPressGestureRecognizer *)holdRecognizer
{
if (UIGestureRecognizerStateRecognized) {
holdLabel.text = @"Holding Correctly. Release Touch when ready.";
holdView.backgroundColor = [UIColor greenColor];
} else if (UIGestureRecognizerStateCancelled){
holdLabel.text = @"Ended";
holdView.backgroundColor = [UIColor redColor];
}
Run Code Online (Sandbox Code Playgroud)
任何建议都会很棒,特别是如果有人知道如何实现一个返回用户触摸设备状态的调用.我查看了开发人员文档并且空洞了.
Bri*_*ian 11
经过几个小时的修补,我找到了一种有效的方法,不确定它是否是最好的方法.结果我需要像下面的代码一样编写它.我没有调用我在viewDidLoad()方法中声明的特定UIGestureRecognizer.
- (void)holdAction:(UILongPressGestureRecognizer *)holdRecognizer
{
if (holdRecognizer.state == UIGestureRecognizerStateBegan) {
holdLabel.text = @"Holding Correctly. Release when ready.";
holdView.backgroundColor = [UIColor greenColor];
} else if (holdRecognizer.state == UIGestureRecognizerStateEnded)
{
holdLabel.text = @"You let go!";
holdView.backgroundColor = [UIColor redColor];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6634 次 |
| 最近记录: |