ios - 尝试在 iOS 应用程序中为 UITableView 创建一个选择栏

标签 ios uitableview

我正在尝试创建一个 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/

相关文章:

IOS - 暂停和取消暂停当前正在播放的音乐

ios - 在精确点以编程方式添加 SKLabelNode

swift - 从一个 ViewController 转到另一个 ViewController 并更新

ios - 如何使用 RxDataSources 避免重复点击 Tableview 上的按钮

ios - 将编辑设置为yes时prepareForSegue方法不起作用

ios - Swift 以编程方式更改字体

iOS:将图像按钮的值传递给类中函数的好方法

ios - 如何在 Cocos2d 中播放音频文件的特定部分

ios - 带有 UITableViewCellStyleValue1 的单元格不显示 detailTextLabel 文本

iOS:将UITableView的起始索引从0改为1显示数组内容