HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 为什么setEditing:animated:和insertRowsAtIndexPaths:导致这个奇怪的编辑风格动画?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个UITableView,我正在切换setEdiTing:animated:on,允许用户插入和删除行.打开编辑时,我想要将新的插入新项目行添加到表格中,然后我希望编辑控件以正常方式进行动画处理.我不希望新的插入新项目行自己动画,使用类似淡入淡出的东西.我希望它只是出现,然后像任何现有的表数据源行一样滑入.

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



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

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

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

按下工具栏上的编辑按钮时,我调用我的UIViewController方法setEdiTing:animated:.在这方法中,@R_672_10673@下……

- (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:导致这个奇怪的编辑风格动画?所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。