我有一个视图(lstabbarview),它支持使用以下方法插入/删除新元素:

- (void)insertItem:(LSTabItem *)item atIndex:(NSUInteger)index animated:(BOOL)animated; 
- (void)removeItemAtIndex:(NSUInteger)index animated:(BOOL)animated;
.

lstabitem是代表我的模型类的对象。每次添加新元素都使用InsertIdem添加:AtIndex:Animated:使用此模型对象内部的信息创建(LStabControl),然后添加到主视图,然后调用LayOutSubViews来重新计算每个的帧子视图。

我刚刚实现了这些操作,但现在不使用“动画”参数,而我想知道在动画时我应该把代码放在哪里应该在哪里处理动画。

这些是相关方法:

- (void)insertItem:(LSTabItem *)item 
           atIndex:(NSUInteger)index 
          animated:(BOOL)animated 
{
    ...
    LSTabControl *tab = [self _configureNewTabControlForItem:item atIndex:index];
    [tabItems insertObject:item atIndex:index]; 
    [tabViews insertObject:tab atIndex:index]; // array which contains all the subviews

    [self setNeedsLayout];
}

- (void)removeItemAtIndex:(NSUInteger)index 
                 animated:(BOOL)animated 
{
    ...
    LSTabControl *tab = [tabViews objectAtIndex:index];
    ...
    [tab removeFromSuperview];

    [tabViews removeObjectAtIndex:index];
    [tabItems removeObjectAtIndex:index];

    [self setNeedsLayout];
}
.

基本上是什么Layoutsubviews之后将每个子视图放在线性水平序列中,在每个子视图之间应用填充。每个子视图都可以具有不同的宽度或高度(它们不是固定大小)。 当一个新元素添加到Animation设置为Yes(允许index= 2)时,我希望从索引+ 1到numberofelements的每个子视图都会向右移动,然后新子视图显示在可用孔中。

我希望显然lstabbarview是可扩展的,所以在我的基础上实现这些方法我不能做出关于Subviews如何按子类安排的假设(例如,子类可能覆盖layoutsubviews并决定在垂直布局中布局元素而不是水平,结果决定在添加新元素时向下移动每个子视图而不是右转......)

我不想知道如何执行动画(我已经知道如何做到这一点),但考虑到我的要求,如何让新的SubView的出现动画的正确方法。

我应该考虑在layoutsubviews内执行所有动画,或者将动画代码放在insertItem / demoredientem内,让layoutsubviews仅计算子视图布局?

感谢

有帮助吗?

解决方案

layoutSubviews意味着单次快速方法。更好地使用您的insertItem:进行动画。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top