ios – 为什么setEditing:animated:和insertRowsAtIndexPaths:导致这个奇怪的编辑风格动画?

ios – 为什么setEditing:animated:和insertRowsAtIndexPaths:导致这个奇怪的编辑风格动画?,第1张

概述我有一个UITableView,我正在切换setEditing:animated:on,允许用户插入和删除行.打开编辑时,我想要将新的插入新项目行添加到表格中,然后我希望编辑控件以正常方式进行动画处理.我不希望新的插入新项目行自己动画,使用类似淡入淡出的东西.我希望它只是出现,然后像任何现有的表数据源行一样滑入. 以下是我当前代码所发生的情况(点击查看大图): 顶行做我想要的 – 它只是滑过,删除 我有一个UItableVIEw,我正在切换setEditing:animated:on,允许用户插入和删除行.打开编辑时,我想要将新的插入新项目行添加到表格中,然后我希望编辑控件以正常方式进行动画处理.我不希望新的插入新项目行自己动画,使用类似淡入淡出的东西.我希望它只是出现,然后像任何现有的表数据源行一样滑入.

以下是我当前代码所发生的情况(点击查看大图):



顶行做我想要的 – 它只是滑过,删除图标淡入.当它消失时,删除图标淡出,行再次展开.

第二行是我自己添加到表中的非数据源行.在出现时,它根本没有动画.插入图标和行一次出现,不会滑入.当它消失时,行会很好地展开,但加号图标会随之滑动.动画正在整个行中发生,而不是加号图标,然后分开行,就像第一行一样.

这是我的代码的快速破解,但我认为提供类文件的链接可能会更好.

按下工具栏上的编辑按钮时,我调用我的UIVIEwController方法setEditing:animated:.在这种方法中,我做了以下……

- (voID)setEditing:(BOol)editing animated:(BOol)animated {    [super setEditing:editing animated:animated];    // keep the table in the same editing mode    [_table setEditing:editing animated:animated];    if (editing) {        [_table insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:_channels.count inSection:0]] withRowAnimation:UItableVIEwRowAnimationNone];    } else {        [_table deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:_channels.count inSection:0]] withRowAnimation:UItableVIEwRowAnimationNone];    }}

这是插入的动画发生的地方.我已经尝试在[_table beginUpdate]和endUpdate中包装整个内容,以及只插入行.似乎都没有产生我想要的干净动画.

任何想法我可能会失踪?整个代码文件在这里:

https://github.com/ryancole/pound-client/blob/master/pound-client/controllers/ChannelListViewController.m#L106-L127

解决方法 超级调用会执行滑动“编辑”动画,因此如果您在其后插入某些内容,则不会参与其中.您要做的是在该调用之前插入行,然后删除该行.您还需要使用不同的布尔值跟踪行.
- (voID)setEditing:(BOol)editing animated:(BOol)animated {    _amEditing = editing;    if (editing) {        [_table insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:_channels.count inSection:0]] withRowAnimation:UItableVIEwRowAnimationNone];    }     [super setEditing:editing animated:animated];    // keep the table in the same editing mode    [self.vIEw setEditing:editing animated:animated];    if (!editing)    {        [_table deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:_channels.count inSection:0]] withRowAnimation:UItableVIEwRowAnimationNone];    }}- (NSInteger)tableVIEw:(UItableVIEw *)tableVIEw numberOfRowsInSection:(NSInteger)section{    return _amEditing ? _channels.count + 1 : _channels.count;}

更新:

倒数第二行的图标仍然有一个奇怪的动画..要解决此问题,您可以添加延迟删除..

if (!editing)    {        [self performSelector:@selector(deleteLastRow) withObject:nil afterDelay:0.25];    }-(voID) deleteLastRow{    [self.vIEw deleteRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:_objects.count inSection:0]] withRowAnimation:UItableVIEwRowAnimationNone];}
总结

以上是内存溢出为你收集整理的ios – 为什么setEditing:animated:和insertRowsAtIndexPaths:导致这个奇怪的编辑风格动画?全部内容,希望文章能够帮你解决ios – 为什么setEditing:animated:和insertRowsAtIndexPaths:导致这个奇怪的编辑风格动画?所遇到的程序开发问题。

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

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

原文地址: https://outofmemory.cn/web/1100269.html

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

发表评论

登录后才能评论

评论列表(0条)

保存