Ios UITableView动画不支持';添加子视图后无法工作
真的!我不明白为什么。以下是我的代码人员:Ios UITableView动画不支持';添加子视图后无法工作,ios,objective-c,uitableview,Ios,Objective C,Uitableview,真的!我不明白为什么。以下是我的代码人员: _tableOne_cloned = [_tableOne mutableCopy]; [_tableOne_cloned setFrame:CGRectMake(-320.0f, [_tableOne frame].origin.y, [_tableOne frame].size.width, [_tableOne frame].size.height)]; [[self view] insertSubview:_tableOne belowSu
_tableOne_cloned = [_tableOne mutableCopy];
[_tableOne_cloned setFrame:CGRectMake(-320.0f, [_tableOne frame].origin.y, [_tableOne frame].size.width, [_tableOne frame].size.height)];
[[self view] insertSubview:_tableOne belowSubview:_bottomActionBar];
[UIView animateWithDuration:2.5 animations:^{
[_tableOne setFrame:CGRectMake(-320.0f, [_tableOne frame].origin.y, [_tableOne frame].size.width, [_tableOne frame].size.height)];
}];
事情很简单:我的屏幕上有一个UITableView。当我按下某个UIButton时,UITableView必须消失,另一个UITableView将从左侧出现
但是,这是行不通的。如果删除要添加新表的行,则新表的效果会非常好
注意:UITableView不符合NSCopying协议,但我创建了一个扩展来支持它
有什么想法吗?当您想从左侧设置动画时
[UIView animateWithDuration:2.5 animations:^{
[_tableOne setFrame:CGRectMake(-320.0f, [_tableOne frame].origin.y, [_tableOne frame].size.width, [_tableOne frame].size.height)];
}completion:^(BOOL finished) {
[_tableOne setFrame:CGRectMake(+320.0f, [_tableOne frame].origin.y, [_tableOne frame].size.width, [_tableOne frame].size.height)];
[UIView animateWithDuration:2.5 animations:^{
[_tableOne setFrame:CGRectMake(0.0f, [_tableOne frame].origin.y, [_tableOne frame].size.width, [_tableOne frame].size.height)];
}];
}];
为什么要复制?为什么不创建另一个新的UITableView并尝试显示它..哦,对不起,我没有解释它。。。我正在编写某种“模拟旋转木马”,我不想用大量未使用的UITableView来压缩内存。因此,我决定克隆我需要的一个,在动画之后,将其设置为nil
mutableCopy
调用mutableCopyWithZone:
方法,该方法是在NSMutableCopying
协议中定义的,而不是NSCopying
协议中定义的。该函数实际上仅适用于具有可变和不可变版本的类,例如NSArray
。你试过只使用[\u tableOne copy]
吗?对于mutableCopy或copy似乎有相同的行为……那么为什么你要为一个并不真正要求实现的类创建一个支持可变复制的扩展呢?其次,为什么要使用copy
?为什么不每次从Nib加载,或者创建一个初始化并返回完全设置的UITableView
的方法呢?好吧,我在x原点上使用-320.0f值,因为我希望UITableView在屏幕外动画。在动画开始时,它是0.0fok,然后使其反向,并将其应用于tableview,您希望将其设置为0.0fYep,但这是我正在试验的奇怪行为。。。没用嗨Yoryo你到底想做什么?是否要将表格从0.0f设置为-320.0f并再次使用is的相同位置设置动画,请尝试我的更新代码。如果有任何查询仍然悬而未决,那么请询问它?如果您看到我上面的代码,您可以注意到,在origin中,我有一个UITableView,坐标x位于0.0f。当我按下一个按钮时,我克隆了它,但克隆的那个按钮的坐标x位于-320.0f。所以我们有两种观点。此时,我想对它们都设置动画,第一个在320.0f上坐标x,克隆的一个在0.0f上坐标x。并最终销毁原始UITableView。