ios – UITouch不释放视图

ios – UITouch不释放视图,第1张

概述我有一个未被解除分配的自定义视图.我按下关闭按钮时关闭控制器.现在如果我只按下按钮,视图就会被解除分配.但是,如果用一根手指按下按钮,其他手指触摸视图,则在解除时不会取消分配,而是在下一次触摸事件中. 它的UITouch保留了我的视图参考而不是释放它.我怎样才能解决这个问题? 这是我的近距离行动的代码: - (IBAction)closePressed:(UIButton *)sender { 我有一个未被解除分配的自定义视图.我按下关闭按钮时关闭控制器.现在如果我只按下按钮,视图就会被解除分配.但是,如果用一根手指按下按钮,其他手指触摸视图,则在解除时不会取消分配,而是在下一次触摸事件中.

它的UItouch保留了我的视图参考而不是释放它.我怎样才能解决这个问题?

这是我的近距离行动的代码:

- (IBAction)closepressed:(UIbutton *)sender {    NSLog(@"Close pressed");     if (self.loader)    [self.loader cancelJsonLoading];    [self.plVIEw quit];    [self dismissVIEwControllerAnimated:YES completion:nil];}
解决方法 你试着打电话:

[self.vIEw resignFirstResponder];

这应取消所有待处理的UItouches.

如果这不起作用,您可以跟踪您的触摸:

>定义存储当前触摸的NSMutableSet:

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];}

我认为,它有点Hacky,但是医生说:

When an object receives a touchesCancelled:withEvent: message it should clean up any state information that was established in its touchesBegan:withEvent: implementation.

总结

以上是内存溢出为你收集整理的ios – UITouch不释放视图全部内容,希望文章能够帮你解决ios – UITouch不释放视图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1030925.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存