Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/100.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 布局子视图中的动画?_Ios_Uiview_Uiviewanimation_Layoutsubviews - Fatal编程技术网

Ios 布局子视图中的动画?

Ios 布局子视图中的动画?,ios,uiview,uiviewanimation,layoutsubviews,Ios,Uiview,Uiviewanimation,Layoutsubviews,我有一个视图(LSTabBarView),它支持使用以下方法插入/删除新元素: - (void)insertItem:(LSTabItem *)item atIndex:(NSUInteger)index animated:(BOOL)animated; - (void)removeItemAtIndex:(NSUInteger)index animated:(BOOL)animated; LSTabItem是表示我的模型类的对象。每次使用insertItem:atIndex:animate

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

- (void)insertItem:(LSTabItem *)item atIndex:(NSUInteger)index animated:(BOOL)animated; 
- (void)removeItemAtIndex:(NSUInteger)index animated:(BOOL)animated;
LSTabItem是表示我的模型类的对象。每次使用insertItem:atIndex:animated添加新元素时:将使用此模型对象内部的信息创建一个新的子视图(LSTabControl),然后将其添加到主视图,最后调用layoutSubviews以重新计算每个子视图的帧

我刚刚实现了这些操作,但是“animated”参数现在还没有使用,我想知道当animated为YES时,我应该把处理动画的代码放在哪里。

以下是相关的方法:

- (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];
}
LayoutSubview所做的基本上是将每个子视图按线性水平顺序依次放置,并在每个子视图之间应用填充。每个子视图可以有不同的宽度或高度(它们不是固定大小)。 当添加新元素时,动画设置为“是”(假设索引=2),我希望从索引+1到numberOfElements的每个子视图都向右移动,然后新的子视图显示在可用的孔中

显然,我希望LSTabBarView是可扩展的,因此在这些方法的基本实现中,我不能假设子视图将如何按子类排列(例如,子类可能会覆盖LayoutSubView,并决定在垂直布局中而不是在水平布局中布局元素,因此在添加新元素时决定将每个子视图向下移动而不是向右移动…)

我不想知道如何执行动画(我已经知道如何执行),但考虑到我的上述要求,如何为新子视图的外观设置动画的正确方法是什么

<强>我应该考虑执行LayOutSubVIEW中的所有动画,还是将动画代码放在插入/删除项中,让LayOutSubVIEW只计算子视图布局?< /强>


感谢
layoutSubviews
意味着一次快速的方法。最好将
插入项:
用于动画。

layoutSubviews
意味着一次快速的方法。最好将
插入项:
用于动画