我有一个没有被释放的自定义视图。按下关闭按钮后,我关闭控制器。现在,如果我只按下按钮,视图就会被释放。但是如果用一根手指按下按钮,另一根手指接触视图,它不会在解除时释放,而是在下一次触摸事件时释放。
它的UITouch保留了我视图的引用,而不是释放它。我该如何解决这个问题呢?
下面是我的关闭操作的代码:
- (IBAction)closePressed:(UIButton *)sender {
NSLog(@"Close pressed");
if (self.loader)
[self.loader cancelJsonLoading];
[self.plView quit];
[self dismissViewControllerAnimated:YES completion:nil];
}发布于 2016-10-17 22:14:33
你有没有试着打电话给:
[self.view resignFirstResponder];这应该会取消所有挂起的UITouches。
如果这不起作用,你可以跟踪你的触摸:
NSMutableSet *_currentTouches;
_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];
}我觉得有点老生常谈,但医生说:
当一个对象接收到一个触摸时,它应该清除在它的触摸中建立的任何状态信息clean :withEvent:implementation。
https://stackoverflow.com/questions/40087761
复制相似问题