1

在我的应用程序中,我想沿点击方向旋转图像视图。还将图像视图移动到点击位置。我已经完成了移动 UIImageView 的代码,但我无法弄清楚如何在点击方向上旋转图像。感谢任何帮助。以下是我移动和旋转的代码。但是旋转并没有给出正确的方向。

-(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){

                     }];

}
4

0 回答 0