在下次触摸之前无法接收系统手势状态通知

时间:2013-11-04 09:43:08

标签: ios objective-c uiviewanimation uipinchgesturerecognizer

我有一个控件可以在视图中交替切换两个视图。即,在容器视图中通过子视图方法添加两个视图控制器。缩小gusture缩放当前视图,并显示第二个视图。如果希望转到上一个视图,那么一个捏出来的风就会这样做。问题在于,视图doest不会对gusture做出反应,有时并非总是如此,而meessage "Failed to receive system gesture state notification before next touch" - 会在日志中打印出来。任何关于为什么这个消息即将来临并且观点不能反复认同的建议?

- (void)scaleHandler:(UIPinchGestureRecognizer *)gestureRecognizer{

CGFloat currentScale = [[[gestureRecognizer view].layer valueForKeyPath:@"transform.scale"] floatValue];
if([gestureRecognizer state] == UIGestureRecognizerStateBegan) {
    // Reset the last scale, necessary if there are multiple objects with different scales
    lastScale = [gestureRecognizer scale];
}

if ([gestureRecognizer state] == UIGestureRecognizerStateBegan ||
    [gestureRecognizer state] == UIGestureRecognizerStateChanged) {

    // Constants to adjust the max/min values of zoom
    CGFloat kMaxScale = 1.0;
    CGFloat kMinScale = 1.0;
    gestureRecognizer.view.alpha = 1/currentScale;
    if ([gestureRecognizer view] == [self.firstView view]) {
        kMaxScale = 10.0;
        kMinScale = 1.0;
        gestureRecognizer.view.alpha = 1/currentScale;
    }

    if ([gestureRecognizer view] == [self.pageView view]) {
        kMaxScale = 1.0;
        kMinScale = 0.1;
        gestureRecognizer.view.alpha = currentScale;
    }


   // NSLog(@"Current Scale is %f",[gestureRecognizer scale]);

    CGFloat newScale = 1 -  (lastScale - [gestureRecognizer scale]);
    newScale = MIN(newScale, kMaxScale / currentScale);
    newScale = MAX(newScale, kMinScale / currentScale);

    CGAffineTransform transform = CGAffineTransformScale([[gestureRecognizer view] transform], newScale, newScale);
    [gestureRecognizer view].transform = transform;

    lastScale = [gestureRecognizer scale];  // Store the previous scale factor for the next pinch gesture call
}

if([gestureRecognizer state] == UIGestureRecognizerStateEnded){

      if ([gestureRecognizer view] == [self.firstView view]) {
        if(currentScale > 1.0f){
            [self setPinchOutAnimationHidden:YES];
        }
        else{
            [self setPinchOutAnimationHidden:NO];
        }
      }
      else{
          if(currentScale < 0.9f){
              [self setPinchInAnimationToHidden:YES];
          }
          else{
              [self setPinchInAnimationToHidden:NO];
          }
      }

}

}

- (void)setPinchInAnimationToHidden: (BOOL)shouldHide{

if(shouldHide){
    NSLog(@"animation 1 - pinch in");
    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        CGAffineTransform transform = CGAffineTransformScale([self.pageView.view transform], 0, 0);
        self.pageView.view.transform = transform;
    } completion:^(BOOL finished){
       // [firstView.view sendSubviewToBack:pageView.view];
        NSLog(@"animation 1 - pinchin completion handler");
        [self.view insertSubview:self.pageView.view belowSubview:self.firstView.view];
        self.pageView.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
        self.pageView.view.alpha = 1.0;
    }];
}
else{
      NSLog(@"animation 2- pinch in");
    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.pageView.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
        self.pageView.view.alpha = 1.0;
    } completion:nil];
}
}

- (void)setPinchOutAnimationHidden: (BOOL)shouldHide{
if(shouldHide){
    NSLog(@"animation 3 - pinch out");
   // firstView = [ViewFactory firstViewController];
    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        CGAffineTransform transform = CGAffineTransformScale([self.firstView.view transform], 15.0, 15.0);
        self.firstView.view.transform = transform;
        self.firstView.view.alpha = 0.0;
    } completion:^(BOOL finished){
           NSLog(@"animation 3 - pinch out - completion handler");
        //[pageView.view sendSubviewToBack:firstView.view];
        [self.view insertSubview:self.firstView.view belowSubview:self.pageView.view];
        self.firstView.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
        self.firstView.view.alpha = 1.0;
    }];
}
else{
     NSLog(@"animation 4- pinch out");
    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.firstView.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
        self.firstView.view.alpha = 1.0;
    } completion:nil];
}
}

1 个答案:

答案 0 :(得分:0)

  

视图不会重新调整手势

注册客人以识别各州

UIPinchGestureRecognizer *pinchGuestureRecog = [UIPinchGestureRecognizer alloc]initWithTarget:self action: @selector(scaleHandler:)];