我有旋转和移动图像(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];
它一次一个地运作良好。但是这两个动画一起不起作用。Space Ship 正在旋转,但没有朝某个方向移动。
我的错在哪里?
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];
}];
现在我的船旋转并移动到水龙头点。在另一个点的第二次点击中,UIView 返回起始坐标,但是....带有动画))