1

In my application i want to rotate the image view in the direction of the tap. An also move the image view to the tap location. I have completed the code for moving the UIImageView but i am not able to figure out how to rotate the Image in the direction of tap.Any help is appreciated. Following is my code to move and rotate. But rotation does not give the correct direction.

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