我正在迭代UITabBar视图:
for (UIView *view in [tabBar subviews]) {
if ([view isKindOfClass:[UIControl class]]) {
tabBarItemFrame = [tabBar convertRect:view.frame toView:self.view];
}
}
订单最初是:
<_UITabBarBackgroundView: 0x7a62e150; frame = (0 0; 768 49); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x7a62fcd0>>,
<GSBadgeView: 0x7b1b6060; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7b1b61d0>>,
<UITabBarButton: 0x7d75ee80; frame = (71 1; 76 48); opaque = NO; layer = <CALayer: 0x7b0eaf80>>,
<UITabBarButton: 0x7d75ef90; frame = (181 1; 76 48); opaque = NO; layer = <CALayer: 0x7b0e7f40>>,
<UITabBarButton: 0x7d75f180; frame = (291 1; 76 48); opaque = NO; layer = <CALayer: 0x7b0c16e0>>,
<UITabBarButton: 0x7d75f6f0; frame = (401 1; 76 48); opaque = NO; layer = <CALayer: 0x7b0278a0>>,
<UITabBarButton: 0x7b026060; frame = (511 1; 76 48); opaque = NO; layer = <CALayer: 0x7b0244d0>>,
<UITabBarButton: 0x7b002960; frame = (621 1; 76 48); opaque = NO; layer = <CALayer: 0x7d7697c0>>,
<UIImageView: 0x7a62fdf0; frame = (0 -1; 768 1); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x7a62bd50>>
退出应用程序并返回后,订单将更改为:
<_UITabBarBackgroundView: 0x7a62e150; frame = (0 0; 768 49); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x7a62fcd0>>,
<GSBadgeView: 0x7b1b6060; frame = (0 0; 0 0); hidden = YES; layer = <CALayer: 0x7b1b61d0>>,
<UITabBarButton: 0x7d75ef90; frame = (181 1; 76 48); opaque = NO; layer = <CALayer: 0x7b0e7f40>>,
<UITabBarButton: 0x7d75f180; frame = (291 1; 76 48); opaque = NO; layer = <CALayer: 0x7b0c16e0>>,
<UITabBarButton: 0x7d75f6f0; frame = (401 1; 76 48); opaque = NO; layer = <CALayer: 0x7b0278a0>>,
<UITabBarButton: 0x7b026060; frame = (511 1; 76 48); opaque = NO; layer = <CALayer: 0x7b0244d0>>,
<UITabBarButton: 0x7b002960; frame = (621 1; 76 48); opaque = NO; layer = <CALayer: 0x7d7697c0>>,
<UIImageView: 0x7a62fdf0; frame = (0 -1; 768 1); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x7a62bd50>>,
<UITabBarButton: 0x7d75ee70; frame = (71 1; 76 48); opaque = NO; layer = <CALayer: 0x7b00ea80>>
差不多,第一个标签栏按钮位于subviews
数组的末尾。视觉上布局是正确的,我没有做任何事来操纵子视图。
任何人都可以提供任何见解吗?我不应该依赖子视图来维护特定的订单吗?
更新
正如@rmaddy在下面提到的那样,挖掘子视图是不必要的。我使用下面的代码获得了适当的框架:
NSInteger helpBarButtonIndex = [self.viewControllers indexOfObject:self.helpMenuVC];
UIView *helpBarButton = [[[self.tabBar items] objectAtIndex:helpBarButtonIndex] view];
tabBarItemFrame = [self.tabBar convertRect:helpBarButton.frame toView:self.view];