TvOS UITabBarController 检测标签栏 shown/hidden
TvOS UITabBarController detect tabbar shown/hidden
有没有办法检测到UITabBarController 的标签栏会出现或消失?我想与 shows/hides 标签栏的动画同时制作动画。
我还没有找到检测此事件的任何方法。标签栏的 属性 "hidden" 不是一个选项,因为它会在动画结束后更改其值
解决方案是使用视图控制器中的方法 didUpdateFocusInContext:withAnimationCoordinator:使用此代码:
static NSString *kUITabBarButtonClassName = @"UITabBarButton";
NSString *prevFocusViewClassName = NSStringFromClass([context.previouslyFocusedView class]);
NSString *nextFocusedView = NSStringFromClass([context.nextFocusedView class]);
// The tabbar is going to disappear
if ([prevFocusViewClassName isEqualToString:kUITabBarButtonClassName] &&
![nextFocusedView isEqualToString:kUITabBarButtonClassName]) {
[self.view layoutIfNeeded];
self.constraintScrollViewCenterY.constant -= self.tabBarController.tabBar.frame.size.height;
[coordinator addCoordinatedAnimations:^{
[self.view layoutIfNeeded];
} completion:nil];
// The tabbar is going to appear
} else if (![prevFocusViewClassName isEqualToString:kUITabBarButtonClassName] &&
[nextFocusedView isEqualToString:kUITabBarButtonClassName]) {
[self.view layoutIfNeeded];
self.constraintScrollViewCenterY.constant += self.tabBarController.tabBar.frame.size.height;
[coordinator addCoordinatedAnimations:^{
[self.view layoutIfNeeded];
} completion:nil];
}
其中self.constraintScrollViewCenterY是与我要根据标签栏移动移动的视图的垂直对齐相关的约束
注意:使用class名称(kUITabBarButtonClassName)而不是[...class]方法是因为UITabBarButton是私有的class
有没有办法检测到UITabBarController 的标签栏会出现或消失?我想与 shows/hides 标签栏的动画同时制作动画。
我还没有找到检测此事件的任何方法。标签栏的 属性 "hidden" 不是一个选项,因为它会在动画结束后更改其值
解决方案是使用视图控制器中的方法 didUpdateFocusInContext:withAnimationCoordinator:使用此代码:
static NSString *kUITabBarButtonClassName = @"UITabBarButton";
NSString *prevFocusViewClassName = NSStringFromClass([context.previouslyFocusedView class]);
NSString *nextFocusedView = NSStringFromClass([context.nextFocusedView class]);
// The tabbar is going to disappear
if ([prevFocusViewClassName isEqualToString:kUITabBarButtonClassName] &&
![nextFocusedView isEqualToString:kUITabBarButtonClassName]) {
[self.view layoutIfNeeded];
self.constraintScrollViewCenterY.constant -= self.tabBarController.tabBar.frame.size.height;
[coordinator addCoordinatedAnimations:^{
[self.view layoutIfNeeded];
} completion:nil];
// The tabbar is going to appear
} else if (![prevFocusViewClassName isEqualToString:kUITabBarButtonClassName] &&
[nextFocusedView isEqualToString:kUITabBarButtonClassName]) {
[self.view layoutIfNeeded];
self.constraintScrollViewCenterY.constant += self.tabBarController.tabBar.frame.size.height;
[coordinator addCoordinatedAnimations:^{
[self.view layoutIfNeeded];
} completion:nil];
}
其中self.constraintScrollViewCenterY是与我要根据标签栏移动移动的视图的垂直对齐相关的约束
注意:使用class名称(kUITabBarButtonClassName)而不是[...class]方法是因为UITabBarButton是私有的class