我正在创建一个测试 tvOS 应用程序。我有一个图像(在 tableview 之外),当未选择“聚焦”时,我希望图像发生变化......我知道苹果已经添加了几种聚焦方法。有人能告诉我当它处于“焦点”时我会使用哪些方法来更改此图像?我将如何使用它? 我会使用这种方法吗:
- (BOOL)tableView:(UITableView *)tableView canFocusRowAtIndexPath:(NSIndexPath *)indexPath
或者我会使用:
- (void)tableView:(UITableView *)tableView didUpdateFocusInContext:(UITableViewFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
请告诉我!谢谢!
最佳答案
如果你想在 UITableViewCell
项目获得焦点时改变图像,那么你应该使用第二种方法。
- (void)tableView:(UITableView *)tableView didUpdateFocusInContext:(UITableViewFocusUpdateContext *)context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
//You can get focused indexPath like below
NSIndexPath *nextIndexPath = [context nextFocusedIndexPath];
// Now get image from data source, I will assume you have an images array
UIImage *image = [_imagesArray objectAtIndex:nextIndexPath.row];
// Set image to image view, assuming you have a property imageView
_imageView.image = image;
}
关于ios - UITableView 和 tvOS 的新方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32915704/