UITableView 和 tvOS 的新方法
UITableView and new methods for tvOS
我正在创建一个测试 tvOS 应用程序。我有一张图片(在 tableview 之外),当未选择 "focused" 时,我希望更改图片...我知道苹果已经添加了几种聚焦方法。有人能告诉我在 "focus" 中我会使用哪些方法来更改此图像吗?我将如何使用它?
我会用这个方法吗:
- (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;
}
我没有在 tvOS 上使用过 UITableView,但似乎如果该项目在 UITable 之外,则使用 table 委托方法无法使其聚焦。但是,您可以使用自定义 class 扩展 UIImageView,然后像这样覆盖:
- (void) didUpdateFocusInContext:(UIFocusUpdateContext *) context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
if (context.nextFocusedView == self){
// change image
self.image = focusedImage;
} else {
// restore view
self.image = normalImage;
}
}
- (void)canBecomeFocused
{
return YES;
}
如果您运行在从 UITableView 导航到 imageView 时遇到困难,您可能需要使用 UIFocusGuide 来桥接这两个区域。
我正在创建一个测试 tvOS 应用程序。我有一张图片(在 tableview 之外),当未选择 "focused" 时,我希望更改图片...我知道苹果已经添加了几种聚焦方法。有人能告诉我在 "focus" 中我会使用哪些方法来更改此图像吗?我将如何使用它? 我会用这个方法吗:
- (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;
}
我没有在 tvOS 上使用过 UITableView,但似乎如果该项目在 UITable 之外,则使用 table 委托方法无法使其聚焦。但是,您可以使用自定义 class 扩展 UIImageView,然后像这样覆盖:
- (void) didUpdateFocusInContext:(UIFocusUpdateContext *) context withAnimationCoordinator:(UIFocusAnimationCoordinator *)coordinator
{
if (context.nextFocusedView == self){
// change image
self.image = focusedImage;
} else {
// restore view
self.image = normalImage;
}
}
- (void)canBecomeFocused
{
return YES;
}
如果您运行在从 UITableView 导航到 imageView 时遇到困难,您可能需要使用 UIFocusGuide 来桥接这两个区域。