UITableViewCell
当识别水龙头时,我的动画会高度显示它的高度.在iOS 9及更低版本中,这个动画很流畅,没有任何问题.在iOS 10测试版中,动画期间出现了一些不和谐的跳跃.有没有办法来解决这个问题?
这是代码的基本示例.
- (void)cellTapped {
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return self.shouldExpandCell ? 200.0f : 100.0f;
}
Run Code Online (Sandbox Code Playgroud)
编辑:9/8/16
这个问题在全球机制中仍然存在.经过更多调试后,我发现问题与单元格立即跳到新高度有关,然后将相关单元格偏移动画.这意味着任何CGRect
依赖于单元格底部的基础动画都不起作用.
例如,如果我有一个约束到单元格底部的视图,它将跳转.解决方案将涉及使用动态常量对顶部的约束.或者想一下另一种方法来定位你的观点,然后再与底层相关.
我正在学习教程中带动画的自动布局
http://weblog.invasivecode.com/post/42362079291/auto-layout-and-core-animation-auto-layout-was
事情很完美.
当我尝试在我的应用程序中使用此概念时,尝试从下到上设置屏幕(UIView)的动画,当设置屏幕只是一个空的UIView时它很有用,
但是如果我将UILabel作为子视图添加到此设置屏幕,动画就会消失.在从设置屏幕中删除此UILabel时,动画可见.
这是我连接的插座
__weak IBOutlet UIView *settingsView;
__weak IBOutlet NSLayoutConstraint *settingsBottomConstraint;
__weak IBOutlet NSLayoutConstraint *settingsViewHeightConstraint;
Run Code Online (Sandbox Code Playgroud)
View确实加载了设置方法(setupViews)
-(void)setupViews
{
settingsBottomConstraint.constant = - settingsViewHeightConstraint.constant;
[settingsView setNeedsUpdateConstraints];
[settingsView layoutIfNeeded];
isSettingsHidden = YES;
}
Run Code Online (Sandbox Code Playgroud)
隐藏/取消隐藏方法
- (IBAction)showSettingsScreen:(id)sender {
if (isSettingsHidden) {
settingsBottomConstraint.constant = 0;
[settingsView setNeedsUpdateConstraints];
[UIView animateWithDuration:.3 animations:^{
[settingsView layoutIfNeeded];
}];
}
else{
settingsBottomConstraint.constant = - settingsViewHeightConstraint.constant;
[settingsView setNeedsUpdateConstraints];
[UIView animateWithDuration:0.3 animations:^{
[settingsView layoutIfNeeded];
}];
}
isSettingsHidden = !isSettingsHidden;
}
Run Code Online (Sandbox Code Playgroud)
我的问题似乎与UIView Auto Layout Animation的问题类似
- (IBAction)btnA:(id)sender {
if(self.height.constant == 300) {
self.height.constant = 50;
} else {
self.height.constant = 300;
}
[self.subView1 setNeedsUpdateConstraints];
[UIView animateWithDuration:1.0 animations:^{
[self.subView1 layoutIfNeeded];
}];
}
Run Code Online (Sandbox Code Playgroud)
我正在使用这个代码,但iOS10
它没有动画它只是跳跃增加和减少mySubview1高度.为什么?
相同的代码工作正常 iOS9