I am using following code to rotate the view when swipeEvent is happened in iPad (using UISwipeGestureRecognizer).But when I continuously does Swipping(2 or 3), the Method is not called, I know the reason , I have used Duration in that method for CABasicAnimation.How can i overvome this problem? anyHelp please?
-(void)handleSwipeFromD开发者_运维技巧:(UISwipeGestureRecognizer *)recognizer
{
NSLog(@"down");
if (operationStart)
{
self.commonLayer = [self.layer presentationLayer];
self.layer.transform = commonLayer.transform;
[self.commonLayer removeAnimationForKey:@"rotationAnimate"];
self.commonLayer = self.layer;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.fromValue = [NSNumber numberWithFloat:0.0 * M_PI];
rotationAnimation.toValue = [NSNumber numberWithFloat:2.0 * M_PI];
//rotationAnimation.toValue = [NSNumber numberWithFloat: 2.5 * 3.15 ];
rotationAnimation.duration = 1.0;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 1.0;
//rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[self.commonLayer addAnimation:rotationAnimation forKey:@"rotationAnimate"];
}
}
The following, placed in the view's controller and not in the view, works like a charm many many times.
- (void)viewDidLoad {
[super viewDidLoad];
UISwipeGestureRecognizer *sw = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFromD:)];
[self.view addGestureRecognizer:sw];
[sw release];
}
-(void)handleSwipeFromD:(UISwipeGestureRecognizer *)recognizer
{
BOOL operationStart = YES;
if (operationStart)
{
//self.view.la
// self.view.commonLayer = [self.layer presentationLayer];
// self.view.layer.transform = commonLayer.transform;
[self.view.layer removeAnimationForKey:@"rotationAnimate"];
CABasicAnimation *rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.fromValue = [NSNumber numberWithFloat:0.0 * M_PI];
rotationAnimation.toValue = [NSNumber numberWithFloat:2.0 * M_PI];
//rotationAnimation.toValue = [NSNumber numberWithFloat: 2.5 * 3.15 ];
rotationAnimation.duration = 1.0;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = 1.0;
//rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
[self.view.layer addAnimation:rotationAnimation forKey:@"rotationAnimate"];
}
}
It is not, however, the same layer hierarchy you have since I removed all "commonLayer" references and I don't really get from your code what role it plays.
精彩评论