gpt4 book ai didi

iOS8 - 如何在 iOS 8 中更改长按手势的灵敏度

转载 作者:行者123 更新时间:2023-12-01 17:50:18 26 4
gpt4 key购买 nike

我有一个 UIView 长按时会翻转。在模拟器中效果很好,但在现实世界中,人的手指在按下时会有微小的 Action 。这些微小的 Action 重置手势并立即触发手势结束状态。

- (void)viewDidLoad {
...

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(didLongPress:)];
longPress.minimumPressDuration = 0.7;
[self.view addGestureRecognizer:longPress];
}


- (void)didLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
if ( gestureRecognizer.state == UIGestureRecognizerStateBegan )
{
[UIView transitionFromView:self.questionCardView toView:self.answerCardView
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:nil];
}
else
{
[UIView transitionFromView:self.answerCardView toView:self.questionCardView
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished){
[self.view addSubview:self.questionCardView];
[self.view sendSubviewToBack:self.questionCardView];
}];
}
}

最佳答案

您需要在手势识别器的处理程序中正确检查手势的状态。

尝试:

- (void)didLongPress:(UILongPressGestureRecognizer *)gestureRecognizer {
if ( gestureRecognizer.state == UIGestureRecognizerStateBegan )
{
[UIView transitionFromView:self.questionCardView toView:self.answerCardView
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromLeft
completion:nil];
}
else if ( gestureRecognizer.state == UIGestureRecognizerStateEnded )
{
[UIView transitionFromView:self.answerCardView toView:self.questionCardView
duration:1.0
options:UIViewAnimationOptionTransitionFlipFromRight
completion:^(BOOL finished){
[self.view addSubview:self.questionCardView];
[self.view sendSubviewToBack:self.questionCardView];
}];
}
}

如您所见, else除了手势结束之外,每个小 Action 都会调用 block 。

关于iOS8 - 如何在 iOS 8 中更改长按手势的灵敏度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33192294/

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