在我的应用程序中,我想在水龙头的方向旋转图像视图。还可以将图像视图移动到点按位置。我已经完成了移动UIImageView的代码,但我无法弄清楚如何在tap方向旋转Image。任何帮助都表示赞赏。以下是我移动和旋转的代码。但轮换并没有给出正确的方向。
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[[event allTouches]anyObject];
touchedPoint= [touch locationInView:touch.view];
[UIImageView animateWithDuration:2.0 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
float rangle11=[self calculate_degree:previousTouchedPoint touchp:touchedPoint];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.5];
[UIView setAnimationDelegate:self];
imageViews.transform = CGAffineTransformMakeRotation(rangle11);
[UIView commitAnimations];
[CATransaction begin];
CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
pathAnimation.duration = 2.0f;
pathAnimation.calculationMode = kCAAnimationPaced;
pathAnimation.fillMode = kCAFillModeForwards;
pathAnimation.removedOnCompletion = NO;
[imageViews.layer setPosition:touchedPoint];
[imageViews.layer addAnimation:pathAnimation forKey:@"animatePosition"];
[CATransaction commit];
previousTouchedPoint = touchedPoint ;
}
completion:^(BOOL finished){
}];
}