iPhone SDK 3.2 UIGestureRecognitor是否干扰UIView动画?

iPhone SDK 3.2 UIGestureRecognitor是否干扰UIView动画?,iphone,animation,iphone-sdk-3.2,gesture-recognition,gesture,Iphone,Animation,Iphone Sdk 3.2,Gesture Recognition,Gesture,手势识别器和用于动画的UIView类方法是否存在已知问题 我在UIGestureRecognitor回调的UIImageView上的一系列动画中遇到问题。如果动画序列是从标准回调(如TouchUpInside)开始的,则动画效果良好。如果通过UILongPressGestureRecognitor启动,则第一个动画跳到末尾,第二个动画立即开始 这里有一个例子说明了我的问题。在项目的.xib中,我有一个连接到ViewToMoveIBMOutlet的UIImageView。我还将一个UIButton

手势识别器和用于动画的UIView类方法是否存在已知问题

我在UIGestureRecognitor回调的UIImageView上的一系列动画中遇到问题。如果动画序列是从标准回调(如TouchUpInside)开始的,则动画效果良好。如果通过UILongPressGestureRecognitor启动,则第一个动画跳到末尾,第二个动画立即开始

这里有一个例子说明了我的问题。在项目的.xib中,我有一个连接到ViewToMoveIBMOutlet的UIImageView。我还将一个UIButton连接到startButton IBOutlet,并将其TouchUpInside操作连接到startButtonClicked IBAction。TouchUpInside动作按我所希望的那样工作,但LongPressGestureRecognitor在大约半秒钟后跳到第一个动画的末尾。当我记录第二个动画(animateTo200)时,我可以看到,当长按启动动画时,它会被调用两次,但当按钮的触碰内部动作启动动画时,它只会被调用一次

- (void)viewDidLoad {
[super viewDidLoad];

UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(startButtonClicked)];
NSArray *recognizerArray = [[NSArray alloc] initWithObjects:longPressRecognizer, nil];
[startButton setGestureRecognizers:recognizerArray];

[longPressRecognizer release];
[recognizerArray release];
}

-(IBAction)startButtonClicked {

if (viewToMove.center.x < 150) {
    [self animateTo200:@"Right to left" finished:nil context:nil];
} else {
    [self animateTo100:@"Right to left" finished:nil context:nil];
}
}

-(void)animateTo100:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:@"Right to left" context:nil];
[UIView setAnimationDuration:4];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animateTo200:finished:context:)];
viewToMove.center = CGPointMake(100.0, 100.0);
[UIView commitAnimations];          
}

-(void)animateTo200:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {
[UIView beginAnimations:@"Left to right" context:nil];
[UIView setAnimationDuration:4];
viewToMove.center = CGPointMake(200.0, 200.0);
[UIView commitAnimations];          
}
-(void)viewDidLoad{
[超级视图下载];
UILongPressGestureRecognizer*longPressRecognizer=[[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(startButtonClicked)];
NSArray*识别器数组=[[NSArray alloc]initWithObjects:longPressRecognizer,nil];
[startButton SetgestureRecognitors:RecognitizerArray];
[长按识别器释放];
[识别器阵列发布];
}
-(iAction)开始按钮单击{
如果(viewToMove.center.x<150){
[自动画200:@“从右到左”完成:无上下文:无];
}否则{
[自动画100:@“从右到左”完成:无上下文:无];
}
}
-(void)animateTo100:(NSString*)animationID已完成:(NSNumber*)已完成上下文:(void*)上下文{
[UIView beginAnimations:@“从右到左”上下文:nil];
[UIView设置动画持续时间:4];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animateTo200:finished:context:)];
viewToMove.center=CGPointMake(100.0,100.0);
[UIView委员会];
}
-(void)animateTo200:(NSString*)animationID已完成:(NSNumber*)已完成上下文:(void*)上下文{
[UIView beginAnimations:@“从左到右”上下文:nil];
[UIView设置动画持续时间:4];
viewToMove.center=CGPointMake(200.0,200.0);
[UIView委员会];
}

您应该将
startButtonClicked
的签名更改为
-(void)startButtonClicked:(UIgestureRegonizer*)手势识别器
,然后在方法中查询手势识别器的
状态
属性。手势识别器将使用不同的状态多次调用其动作方法(例如,
UIGestureRecognitzerStateStart
UIGestureRecognitzerStateEnded
)。

您应该将
startButtonClicked
的签名更改为
-(void)startButtonClicked:(UIGestureRegonizer*)然后在方法中查询手势识别器的
状态
属性。手势识别器将使用不同的状态多次调用其动作方法(例如,
UIgestureRecognitizerStateBegind
UIgestureRecognitizerStateEnded
)。

注意:也要确保编辑动作:
@选择器(startButtonClicked:)
。那就需要结肠了。多亏了两者。这解决了我的问题。下次需要更仔细地阅读文档。注意:也要确保编辑操作:
@selector(startButtonClicked:)
。那就需要结肠了。多亏了两者。这解决了我的问题。下次需要更仔细地阅读文档。