繁体   English   中英

UISwipeGestureRecognizer无法正常工作?

[英]UISwipeGestureRecognizer is not working?

我在iPad上发生swipeEvent时使用以下代码旋转视图(使用UISwipeGestureRecognizer)。但是,当我连续执行Swipping(2或3)时,未调用Method,我知道原因,在该方法中使用了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"];

  }  
}

以下内容放置在视图的控制器中,而不是放置在视图中,很多时候都像一个超级按钮一样工作。

- (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”引用以来,就没有相同的层层次结构,并且我并没有从代码中真正获得它所扮演的角色。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM