我有一個非常簡單的問題,但我無法找到此錯誤的原因。任何想法讚賞。所以,我有一個UIImageView
的對象,並將它從點A(x1,y1)滑動到點B(x2,y2)到點C(x2,y2),等等......錯誤修復移動對象並設置新座標
當我從A移動到B到C到D等等... 沒有動畫,它的工作原理!
當我從一個將它移動到B到C ....等等...... 動畫 - >有一個錯誤!只有A到B的作品,B到C,等等出現在其他地方。
我基本上實行touchesBegan
方法,並touchesEnd
方法和對象移動到新位置與
//NO ANIMATION ==> Works !
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"End of touch");
UITouch *touch = [[event touchesForView:self.view] anyObject];
CGPoint location = [touch locationInView:touch.view];
object.center = CGPointMake(location.x, location.y);
}
..
//ADDING ANIMATION ==> Bug !
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"End of touch");
UITouch *touch = [[event touchesForView:self.view] anyObject];
CGPoint location = [touch locationInView:touch.view];
[self spinLayer:object.layer duration:1 direction:SPIN_CLOCK_WISE newFrame:location];
tempFrame = location; // tempFrame is global.
}
而在動畫的最後,我做
- (void)animationDidStop:(CAAnimation *)theAnimation finished:(BOOL)flag {
object.center = tempFrame;
// I assign this because the object has to be updated to its new location to move it to points B, C, D and so forth...
// The object is actually at the desired point. But it appears on the SCREEN at a different location although it `NSLogs` at the right point.
}
這是錯誤:
當我分配object.center = tempFrame;
我希望對象是在(x2,y2)上。它在技術上是(x2,y2)(當我找到的位置時),但它出現在屏幕上的其他地方。
如果我再次將它移動到點C,它將使用(x2,y2)並正確移動到(x3,y3),但它會再次出現在屏幕上的其他位置!
任何想法??????
我們可以看到該方法'spinLayer:持續時間:方向:newFrame的:'? – joerick 2011-12-29 13:41:01
當然。它只是簡單的動畫... http://pastebin.com/P0ypj7RY – Legolas 2011-12-29 13:44:32
爲什麼不動畫keypath'position.x'和'postion.y'而不是'transform.translate.X/Y'?我檢查了位置上的動畫並且工作得很好 – 2011-12-29 14:38:47