使 tvOS tableview 行在滚动时保持在固定位置
Make tvOS tableview row stay in fixed position while scrolling
我希望使用 UITableView 重现 Netflix tvOS 应用程序的滚动行为。
当您在 Netflix 上滚动浏览应用程序的项目时,焦点行和即将到来的行始终位于同一位置。
使用 UITableView 的默认行为,焦点行的位置因行而异。
我怎样才能做到这一点?
UIScrollViewDelegate
方法 scrollViewWillEndDragging:withVelocity:targetContentOffset:
将允许您控制焦点引擎在滚动视图上设置的内容偏移量:如果您调整 targetContentOffset
参数指向的值,然后焦点引擎将滚动到那里。
所以你应该实现那个方法,并使用你喜欢的任何方法来计算正确的偏移量应该是多少,然后在指针中设置值:
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
CGPoint defaultOffset = *targetContentOffset;
CGPoint newOffset = myFunctionThatAdjustsTheOffset(defaultOffset);
*targetContentOffset = newOffset;
}
我希望使用 UITableView 重现 Netflix tvOS 应用程序的滚动行为。
当您在 Netflix 上滚动浏览应用程序的项目时,焦点行和即将到来的行始终位于同一位置。
使用 UITableView 的默认行为,焦点行的位置因行而异。
我怎样才能做到这一点?
UIScrollViewDelegate
方法 scrollViewWillEndDragging:withVelocity:targetContentOffset:
将允许您控制焦点引擎在滚动视图上设置的内容偏移量:如果您调整 targetContentOffset
参数指向的值,然后焦点引擎将滚动到那里。
所以你应该实现那个方法,并使用你喜欢的任何方法来计算正确的偏移量应该是多少,然后在指针中设置值:
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset
{
CGPoint defaultOffset = *targetContentOffset;
CGPoint newOffset = myFunctionThatAdjustsTheOffset(defaultOffset);
*targetContentOffset = newOffset;
}