我有一个表格 View ,当按下按钮时,我会动画到一个新位置。它覆盖了屏幕底部的一小部分,然后按下按钮调用一个方法,使其覆盖大约一半的屏幕。这样用户可以从表格 View 中选择一个文件。
但是,似乎当我调用 reloadData 时,表格 View 会移回其原始位置,我想阻止这种情况发生,这样用户就不需要每次都按下按钮(例如删除文件、重命名文件或将新文件添加到 TableView 中)。
任何想法我怎么能做到这一点?
我已经包含了代码。文件 IBAction 是按下按钮时发生的事情。
-(IBAction)file:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
if (self.tableView.frame.origin.y == 457) {
[self tableAppear];
}
else {
[self tableDisappear];
}
}
-(void)tableDisappear {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
if ([[UIScreen mainScreen] bounds].size.height == 568) { [self.tableView setCenter:CGPointMake(160, 545)];
}
else { [self.tableView setCenter:CGPointMake(160, 545)];
}
[UIView commitAnimations];
}
-(void)tableAppear {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.2];
if ([[UIScreen mainScreen] bounds].size.height == 568) { [self.tableView setCenter:CGPointMake(160, 390)];
}
else { [self.tableView setCenter:CGPointMake(160, 390)];
}
[UIView commitAnimations];
}
最佳答案
这很可能是自动布局的结果(当需要重绘屏幕时,所有 View 将恢复到由其约束确定的位置,而不是您设置的任何帧)。您可以关闭自动布局以查看是否是问题所在。如果要使用自动布局,则需要使用约束而不是设置 View 来移动或调整 View 大小。
关于ios - 如何阻止 reloadData 移动 TableView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22901777/