title: How to disable/enable a UIPanGestureRecognizer with two separate UIBarButtonItems?
body: <p>I am trying to turn off a <code>UIPanGestureRecognizer</code> with the click of a "Save" button. Then, I am trying to turn back on this <code>UIPanGestureRecognizer</code> with the click of an "Edit" button. I can figure out how to turn them off with the following code like this: </p>
  
  <pre><code>- (IBAction)saveButton:(id)sender {
  
  buttonCount ++;
  if (buttonCount &gt; 0) {
  
      for (_buttonField in self.view.subviews) {
          _buttonField.gestureRecognizers = nil;
  
          _buttonField.layer.borderColor = [UIColor blackColor].CGColor;
  
  
      }
      }
      }
  </code></pre>
  
  <p>Yet, I have two problems. First of all, this is turning off all of the gesture recognizers, which I do not want to do. Secondly, I cannot figure out how to turn them back on. For this I have tried the following:</p>
  
  <pre><code>- (IBAction)editButton:(id)sender {
  
  buttonCount ++;
  if (buttonCount &gt; 0) {
  
      if ([[UIColor colorWithCGColor:_buttonField.layer.borderColor] isEqual:[UIColor whiteColor]]) {
  
      for (_buttonField in self.view.subviews) {
          _buttonField.gestureRecognizers = YES;
  
      }
  }
  }
  }
  </code></pre>
  
  <p>However, I receive an error on the line of code that is set to YES.</p>
  
  <p>Here is my complete set of code for reference:</p>
  
  <pre><code>@implementation FieldGoalChartViewController
  {
  
  
  }
  
  -(void)viewDidLoad{
  [super viewDidLoad];
  
  
  
  
  }
  
  
  
  - (void)touchesBegan:(NSSet&lt;UITouch *&gt; *)touches withEvent:(nullable UIEvent *)event {
  UITouch *aTouch = [touches anyObject];
  
  CGRect buttonRect = self.buttonField.frame;
  
  
  CGPoint point = [aTouch locationInView:self.buttonField.superview];
  
  
  
  if (!CGRectContainsPoint(buttonRect, point)) {
          _buttonField.layer.borderColor = [UIColor blackColor].CGColor;
          _draggedView.layer.borderColor = [UIColor blackColor].CGColor;
      for (_buttonField in self.view.subviews) {
          _buttonField.layer.borderColor = [UIColor blackColor].CGColor;
  
      }
  
      }
  
  
      }
  
  - (void)longPress:(UILongPressGestureRecognizer*)gesture {
  if ( gesture.state == UIGestureRecognizerStateBegan ) {
      gesture.view.layer.borderColor = [UIColor whiteColor].CGColor;
  
  
      UIAlertController * alert=   [UIAlertController
                                    alertControllerWithTitle:@"Would you like to delete the selected rep(s)?"
                                    message:nil
                                    preferredStyle:UIAlertControllerStyleAlert];
  
      UIAlertAction* deleteButton = [UIAlertAction
                                  actionWithTitle:@"Delete"
                                  style:UIAlertActionStyleDefault
                                  handler:^(UIAlertAction * action)
  
                                     {
                                         for (_buttonField in self.view.subviews) {
                                             if ([[UIColor colorWithCGColor:_buttonField.layer.borderColor] isEqual:[UIColor whiteColor]]) {
  
                                                 [_buttonField removeFromSuperview];
  
                                             }
                                         }
  
                                      [alert dismissViewControllerAnimated:YES completion:nil];
  
                                  }];
      UIAlertAction* cancelButton = [UIAlertAction
                                 actionWithTitle:@"Cancel"
                                 style:UIAlertActionStyleDefault
                                 handler:^(UIAlertAction * action)
                                     {
  
  
  
  
  
  
                                     [alert dismissViewControllerAnimated:YES completion:nil];
  
                                 }];
  
      [alert addAction:deleteButton];
      [alert addAction:cancelButton];
  
      [self presentViewController:alert animated:YES completion:nil];
      }
      }
  
  
  
  
      - (void)panWasRecognized:(UIPanGestureRecognizer *)panner {
  
      {
  
      panner.view.layer.borderColor = [UIColor whiteColor].CGColor;
  
  
     _draggedView = panner.view;
  
      CGPoint offset = [panner translationInView:_draggedView.superview];
      CGPoint center = _draggedView.center;
      _draggedView.center = CGPointMake(center.x + offset.x, center.y + offset.y);
      _draggedView.layer.masksToBounds =YES;
      _buttonField.layer.borderWidth = 3.0f;
  
  
  
  
      // Reset translation to zero so on the next `panWasRecognized:` message, the
      // translation will just be the additional movement of the touch since now.
      [panner setTranslation:CGPointZero inView:_draggedView.superview];
  
      }
  
      }
  
  
  
  -(void)buttonTouched:(UIButton*)sender forEvent:(id)tap {
  NSSet *touches = [tap allTouches];
  UITouch *touch = [touches anyObject];
  UITouchPhase *phase = touch.phase;
  touch.view.layer.borderColor = [UIColor whiteColor
                                  ].CGColor;
  }
  
  
  -(void)doubleTapped:(UIButton*)sender forEvent:(id)twoTaps {
  NSSet *touches = [twoTaps allTouches];
  UITouch *touch = [touches anyObject];
  UITouchPhase *phase = touch.phase;
  touch.view.layer.borderColor = [UIColor blackColor].CGColor;
  
  }
  - (IBAction)saveButton:(id)sender {
  
  buttonCount ++;
  if (buttonCount &gt; 0) {
  
      for (_buttonField in self.view.subviews) {
          _buttonField.gestureRecognizers = nil;
  
          _buttonField.layer.borderColor = [UIColor blackColor].CGColor;
  
  
      }
      }
    }
  
  - (IBAction)editButton:(id)sender {
  
  buttonCount ++;
  if (buttonCount &gt; 0) {
  
      if ([[UIColor colorWithCGColor:_buttonField.layer.borderColor] isEqual:[UIColor whiteColor]]) {
  
      for (_buttonField in self.view.subviews) {
          _buttonField.gestureRecognizers = YES;
  
      }
  }
  }
  }
  
  
  - (IBAction)addRepButton:(UIBarButtonItem *)newRep {
  
  self.labelCounter++;
  
  buttonCount ++;
  if (buttonCount &gt; 0 )
  {
  
      _buttonField = [[UIButton alloc]initWithFrame:CGRectMake(300, 300, 28, 28)];
      [_buttonField setTitle:[NSString stringWithFormat:@"%i", self.labelCounter]forState:UIControlStateNormal];
      [_buttonField setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
      _buttonField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
      _buttonField.userInteractionEnabled = YES;
      _buttonField.layer.cornerRadius = 14;
      _buttonField.layer.borderColor = [UIColor blackColor].CGColor;
      _buttonField.layer.borderWidth = 3.0f;
      _buttonField.titleLabel.font = [UIFont boldSystemFontOfSize:13];
      [_buttonField setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
      _buttonField.layer.backgroundColor = [UIColor blackColor].CGColor;
      _buttonField.layer.masksToBounds = YES;
  
      //Pan gesture declared in button
      UIPanGestureRecognizer *panner = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panWasRecognized:)];
      [_buttonField addGestureRecognizer:panner];
  
      //Long Press gesture declared in button
      UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];
      [self.buttonField addGestureRecognizer:longPress];
  
      //Touch down inside declared in button
      [self.buttonField addTarget:self action:@selector(buttonTouched:forEvent:) forControlEvents:UIControlEventTouchDown];
  
      //Double Tap inside declared in button
      [self.buttonField addTarget:self action:@selector(doubleTapped:forEvent:) forControlEvents:UIControlEventTouchDownRepeat];
  
      [self.view addSubview:(_buttonField)];
  
  
  
  
  }
  
  
  }
  
  
  
  
  
  
  
  @end
  </code></pre>
  
  <p>I want to know how to specifically turn off the <code>UIPanGestureRecognizer</code> with the click of my "Save" <code>UIBarButton</code>, and then turn the <code>UIPanGestureRecognizer</code> with the click of my "Edit" <code>UIBarButton</code>.</p>