1

iPadでswipeEventが発生したときに(UISwipeGestureRecognizerを使用して)次のコードを使用してビューを回転させています。 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 に答える