gpt4 book ai didi

iphone - UILongPressGestureRecognizer 不工作

转载 作者:行者123 更新时间:2023-11-28 23:07:10 27 4
gpt4 key购买 nike

我正在尝试创建一个应用程序,其中可以在触发 UILongPressGestureRecognizer 手势时拖放 UIButton。实际上,我的应用程序在任何 iPad 上都运行良好。它仅在 iPhone 中产生问题并且低于 iOS 5.0 menas 它在 iOS 5.0 的 iPhone 中工作正常。

UILongPressGestureRecognizer * gesture = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @selector(moveActionGestureRecognizerStateChanged:)];
gesture.minimumPressDuration = 0.5;
gesture.delegate = self;
[self.dragView addGestureRecognizer: gesture];
[gesture release];

- (void) moveActionGestureRecognizerStateChanged: (UILongPressGestureRecognizer *) recognizer
{
switch ( recognizer.state )
{
default:
case UIGestureRecognizerStateFailed:
{
dragView.alpha=1.0;
[dragView release];
dragView=nil;
break;
}
case UIGestureRecognizerStatePossible:
{
dragView.alpha=0.8;
dragView.frame=CGRectMake(dragView.frame.origin.x, dragView.frame.origin.y, dragView.frame.size.width, dragView.frame.size.height);
}
case UIGestureRecognizerStateCancelled:
{
dragView.alpha=1.0;
[dragView release];
dragView=nil;
break;
}
case UIGestureRecognizerStateEnded:
{
//Set dragView on target position

break;
}
case UIGestureRecognizerStateBegan:
{
//NSLog(@"Began");
dragView.alpha=0.8;
dragView.frame=CGRectMake(dragView.frame.origin.x, dragView.frame.origin.y, dragView.frame.size.width, dragView.frame.size.height);
[self bringSubviewToFront:dragView];
break;
}
case UIGestureRecognizerStateChanged:
{
[self.view bringSubviewToFront:dragView];
CGPoint offset = [recognizer locationInView: self.scrollView];
dragView.frame=CGRectMake(offset.x, offset.y, dragView.frame.size.width, dragView.frame.size.height);
}
break;
}
}

我有 2 台设备 iPhone 3G,iOS 4.2.1 和 iPhone 4,iOS 5.0。此功能在装有 iOS 5.0 的 iPhone 4 中运行良好,但在装有 iOS 4.2.1 的 iPhone 3g 中无法正常运行。有时它在 iPhone 3g 中工作,但有时它不调用委托(delegate)方法。

如果您对此有任何解决方案,请告诉我。

谢谢!

最佳答案

委托(delegate)方法是根本没有被调用,还是没有被选中?我不知道这是否真的解决了你的问题,但你应该修复你的 switch (在默认情况下抢劫):

switch ( recognizer.state )
{
case someCase:
{
// ...
break;
}

default:
break;
}

关于iphone - UILongPressGestureRecognizer 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9141472/

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