1

我正在使用以下代码在 iPad 中发生 swipeEvent 时旋转视图(使用 UISwipeGestureRecognizer)。但是当我连续执行 Swipe(2 或 3)时,没有调用该方法,我知道原因,我在该方法中使用了 Duration对于 CABasicAnimation。我怎样才能克服这个问题?请问有什么帮助吗?

-(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"];

  }  
}
4

1 回答 1

3

以下,放置在视图的控制器中而不是在视图中,多次像魅力一样工作。

- (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"];

    }  
}

但是,自从我删除了所有“commonLayer”引用以来,它与您所拥有的层层次结构不同,而且我并没有真正从您的代码中得到它所扮演的角色。

于 2010-12-30T09:20:19.773 回答