我正在尝试创建一个 UITableView,它有一个选择栏,可以滚动到用户选择的任何一行(请不要问为什么,我只需要这样做)。这与 UITableView 的典型选择栏不同,因为那里没有动画。我所做的是在 Interface Builder 中将一个 TableView 添加到我的主视图,并且我还在我的主视图中添加了一个 imageView。我需要它的工作类似于 UIPickerView 中的选择栏,除了在这种情况下它是移动的选择栏。我认为此代码将位于内部:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
_imageView.frame = rect;
}
任何人都可以向我解释如何对单元格之间的选择栏动画进行编码吗?
提前感谢所有回复的人
最佳答案
假设您当前的代码有效:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[UIView animateWithDuration:.3 animations:^{
CGRect rect = [tableView rectForRowAtIndexPath:indexPath];
_imageView.frame = rect;
}];
}
还有+animateWithDuration:animations:completion:和 +animateWithDuration:delay:options:animations:completion:
关于ios - 尝试在 iOS 应用程序中为 UITableView 创建一个选择栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16947852/