【发布时间】:2012-08-06 11:09:28
【问题描述】:
今天 animateWithDuration 表现得非常愚蠢,我不知道为什么。我检查了所有的东西,所有的括号,一切都很完美,但它总是显示我没有指定为动画的代码行。
好的,这就是重点。我有一个 longPressGestureRecognizer。在 longPress 开始后,它位于一些正在拖动的 UIImageView 上。当它在某个特殊区域结束时,我想开始动画,将 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;
}
情况是由于某种奇怪的原因,上面的两行代码得到了动画,而不是指定的真实动画。我通过将 cmets 放在这些代码行上进行了仔细检查 - 在这种情况下,动画效果很好。
谁能帮我解决这个问题,为什么会这样?这似乎是一种非常奇怪的行为。
【问题讨论】:
-
你指的是哪两行???原则上,动画应该在以下两行执行: self.frame = CGRectMake(newPlaceForCharacter.frame.origin.x-8, newPlaceForCharacter.frame.origin.y-5, 40, 55); self.alpha = 0.5;
-
我的意思是这两个:translatedPoint = CGPointMake(initialX, initialY); [[发件人视图] setCenter:translatedPoint];
-
我知道应该发生什么,但它不知道,这很奇怪。
标签: ios animation uigesturerecognizer