簡體   English   中英

iPhone SDK 3.2 UIGestureRecognizer會干擾UIView動畫嗎?

[英]iPhone SDK 3.2 UIGestureRecognizer interfering with UIView animations?

手勢識別器和用於動畫的UIView類方法是否存在已知問題?

我在UIGestureRecognizer回調的UIImageView上播放一系列動畫時遇到問題。 如果動畫序列是從標准回調(如TouchUpInside)開始的,則動畫效果很好。 如果通過UILongPressGestureRecognizer啟動,則第一個動畫將跳到結尾,第二個動畫立即開始。

這是一個說明我的問題的示例。 在項目的.xib中,我有一個UIImageView,它已連接到viewToMove IBOutlet。 我還將UIButton連接到startButton IBOutlet,並將其TouchUpInside操作連接到startButtonClicked IBAction。 TouchUpInside操作可以按我希望的方式工作,但是longPressGestureRecognizer在大約半秒鍾后跳到第一個動畫的結尾。 當我NSLog第二個動畫(animateTo200)時,我可以看到它在長按開始動畫時被調用了兩次,而在按鈕的TouchUpInside操作開始動畫時僅被調用了一次。

- (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];          
}

您應該將startButtonClicked的簽名更改為- (void)startButtonClicked:(UIGestureRegognizer *)gestureRecognizer ,然后在該方法中查詢手勢識別器的state屬性。 手勢識別器將以不同的狀態(例如UIGestureRecognizerStateBeganUIGestureRecognizerStateEnded )多次調用其操作方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM