After some serious thought in solving this issue, I realised that it was a trivial mistake. The flicker was caused because I am making the rotation for even slightest change in drag direction. To solve this, I assumed an arbitrary margin of pixel-change before I make rotation.
The modified code that solved the issue is as below
- (void) pan:(UIPanGestureRecognizer*) gesture {
if(gesture.state==UIGestureRecognizerStateBegan) {
CGPoint anchor = [gesture locationInView:gesture.view];
gesture.view.layer.anchorPoint = CGPointMake(anchor.x/gesture.view.bounds.size.width,
anchor.y/gesture.view.bounds.size.height);
}
else if(gesture.state==UIGestureRecognizerStateChanged) {
CGPoint point1 = [gesture locationInView:self.view];
gesture.view.layer.position=point1;
CGPoint velocity = [gesture velocityInView:gesture.view];
CGFloat angle = 0.0;
if(velocity.x > self.view.bounds.size.width*0.15)
{
// Dragged right
if(velocity.y > self.view.bounds.size.height*0.02) {
// Dragged down
// counter clock
angle = -0.05;
}
else if (velocity.y < -self.view.bounds.size.height*0.02) {
// Dragged up
// clock
angle = 0.05;
}
}
else if (velocity.x < -self.view.bounds.size.width*0.15)
{
// Dragged left
if(velocity.y > self.view.bounds.size.height*0.02) {
// Dragged down
// clock
angle = 0.05;
}
else if (velocity.y < -self.view.bounds.size.height*0.02) {
// Dragged up
// counter clock
angle = -0.05;
}
}
[self applyRotationToView:gesture.view byAngle:angle];
}
}
- (void) applyRotationToView:(UIView*)rotationView byAngle:(CGFloat)angle {
rotationView.transform = CGAffineTransformRotate(rotationView.transform, angle);
}
Animations are still not as smooth as one would expect, however I have managed to reduce the annoying flicker.