画像(UIView)の回転と移動に問題があります。
これを回転に使用する場合:
[UIView beginAnimations: @"rotate" contex: nil];
[UIView setAnimationDuration: 1];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
spaceShip.transform = CGAffineTransformMakeRotation (angle); // spaceShip is the UIView
[UIView commitAnimations];
そしてこれを動かす:
[UIView beginAnimations: @"move" contex: nil];
[UIView setAnimationDuration: 1];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
spaceShip.center = destanation // destanation is a point where user tap
[UIView commitAnimations];
ひとつひとつうまくいっています。しかし、この 2 つのアニメーションを一緒に使用することはできません。宇宙船は回転していますが、方向は変わりません。
私の間違いはどこですか?
PSアーリーアンカーポイント(0.5、0.5)を指定しました。しかし、画像を回転させると座標が変わります。
更新:
ブロックベースの方法を使用。このような
- (void) viewDidLoad
{
[spaceShip.layer setAnchorPoint: CGPointMake(0.5, 0.5)];
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *tap = [[event allTouches] anyObject];
destanationPoint = [tap locationInView: tap.view];
NSLog(@"%0.3f", angle*180/M_PI);//Just for monitoring
[UIView animateWithDuration:1.0
delay: 0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
spaceShip.transform = CGAffineTransformMakeRotation(angle);
}
completion:^(BOOL finished){
// Wait one second and then fade in the view
[UIView animateWithDuration:1.0
delay: 1.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
spaceShip.center = destanationPoint;
}
completion:nil];
}];
}
その方法は有効です。ただし、新しいタップごとにUIImageが開始位置の座標を変更します。わかりました、追加してみました:
options: UIViewAnimationOptionCurveEaseOut |
UIViewAnimationOptionBeginFromCurrentState
しかし、それは助けにはなりません。
UPD2
これを試してください:
[UIView animateWithDuration:1.0
delay: 0.0
options: UIViewAnimationOptionCurveEaseOut |
UIViewAnimationOptionBeginFromCurrentState
animations:^{
spaceShip.transform = CGAffineTransformMakeRotation(angle);
spaceShip.center = destanationPoint;
}
completion:^(BOOL finished){
// Wait one second and then fade in the view
[UIView animateWithDuration:1.0
delay: 1.0
options: UIViewAnimationOptionCurveEaseOut |
UIViewAnimationOptionBeginFromCurrentState
animations:^{
spaceShip.center = destanationPoint;
}
completion:nil];
}];
今、私の船は回転し、タップポイントに移動します. 別のポイントでの2回目のタップで UIView は開始座標に戻りますが....アニメーション付き ))