gpt4 book ai didi

ios - animateWithDuration 基于完全不相关的代码行执行动画

转载 作者:行者123 更新时间:2023-11-29 04:32:46 28 4
gpt4 key购买 nike

今天 animateWithDuration 表现得很愚蠢,我不知道为什么。我检查了所有的东西,所有的括号,一切都很完美,但它总是呈现我没有指定为动画的代码行。

好的,这就是重点。我有一个 longPressGestureRecognizer。它位于某个 UIImageView 上,在长按开始后正在拖动该 View 。当它在某个特殊区域结束时,我想开始动画,将 UIImageView 带到其他地方并完成它。这是我的代码:

if ([(UILongPressGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {
CGPoint dropPoint = CGPointMake(self.center.x, self.center.y-5);
for (UIView * placeForCharacter in delegate.subviews) {
if ([placeForCharacter isKindOfClass:[PlaceForCharacterCircle class]]) {
PlaceForCharacterCircle * newPlaceForCharacter = (PlaceForCharacterCircle *) placeForCharacter;
if (CGRectContainsPoint(newPlaceForCharacter.dropZone, dropPoint)) {
UIViewAnimationOptions options = 0;
[UIView animateWithDuration:0.2 delay:0.0 options:0 animations:^{
self.frame = CGRectMake(newPlaceForCharacter.frame.origin.x-8, newPlaceForCharacter.frame.origin.y-5, 40, 55);
self.alpha = 0.5;
}
completion:^(BOOL finished){
NSLog(@"animation completed");
self.alpha=1;
//code referring to the finalizing of moving, doesn't matter here
return;
}];
} else {
if (CGRectContainsPoint(newPlaceForCharacter.dropZone, dropPoint)) {
//code referring to the moving to the other place in case the UIImageView was dropped on another zone that is full already, doesn't matter here
return;
}
}
}
}
//code referring to the comeback of a UIImageView in case it was dropped somewhere else, doesn't matter here
//These two are the lines that get executed when the animation starts
//THEY BEGIN
translatedPoint = CGPointMake(initialX, initialY);
[[sender view] setCenter:translatedPoint];
//THEY END
return;
}

情况是,由于某种奇怪的原因,上面的两行代码被动画化,而不是指定的真实动画。我通过在这些代码行上添加注释来仔细检查它 - 在这种情况下,动画效果很好。

有人可以帮我解决这个问题吗?为什么会发生这种情况?这似乎是一种非常奇怪的行为。

最佳答案

如果将 return; 从完成 block (它不执行任何操作)移动到动画设置之后,它应该可以工作。

[UIView animateWithDuration:0.2 delay:0.0 options:0 animations:^{
self.frame = CGRectMake(newPlaceForCharacter.frame.origin.x-8, newPlaceForCharacter.frame.origin.y-5, 40, 55);
self.alpha = 0.5;
}
completion:^{
NSLog(@"animation completed");
self.alpha=1;
//code referring to the finalizing of moving, doesn't matter here
}];
return;

关于ios - animateWithDuration 基于完全不相关的代码行执行动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11495647/

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