UITouch does not release a view

I have a custom view that is not freed. I reject the controller on the pressed button. Now, if I just click the button, the view is freed up in order. But if you press the button with one finger with the other finger, touching the view that it does not exempt from dismissal, but in the next touch event.

Its a UITouch that keeps a link in my opinion and doesn't release it. How can i fix this?

Here is my code for my action:

- (IBAction)closePressed:(UIButton *)sender {
    NSLog(@"Close pressed"); 
    if (self.loader)
    [self.loader cancelJsonLoading];
    [self.plView quit];
    [self dismissViewControllerAnimated:YES completion:nil];
}
+4
source share
1 answer

You tried to call:

[self.view resignFirstResponder];

This should cancel all pending UITs.

If this does not work, you can track your touch:

  • define an NSMutableSet where you save current touches:

    NSMutableSet *_currentTouches;

  • init():

    _currentTouches = [[NSMutableSet alloc] init];

:

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super.touchesBegan:touches withEvent:event];
    [_currentTouches unionSet:touches]; // record new touches
}

- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super.touchesEnded:touches withEvent:event];
    [_currentTouches minusSet:touches]; // remove ended touches
}

- (void)touchesCancelled:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [super.touchesEnded:touches withEvent:event];
    [_currentTouches minusSet:touches]; // remove cancelled touches
}

, (, ):

- (void)cleanCurrentTouches {
    self touchesCancelled:_currentTouches withEvent:nil];
    _currentTouchesremoveAllObjects];
}

, , , :

Cancelled: withEvent: message it , ​​ touchesBegan: withEvent: .

+1

Source: https://habr.com/ru/post/1657995/


All Articles