2014-02-07 124 views
0

我的应用程序使用标签栏控制器使用故事板。在第一次通过应用程序时,我想在每个选项卡栏按钮上使用UIPoppver。然而,要做到这一点,我需要知道每个CGRect(我认为)。我如何去做这件事?在标签栏控制器按钮/图标上显示UIPopover

enter image description here

+0

[获取一个特定的选项卡栏项的帧](HTTP的可能重复:// stackoverflow.com/questions/6325457/getting-the-frame-of-a-particular-tab-bar-item) –

+0

谢谢,我如何引用我的TabBarController,因为它使用故事板连接起来,而且没有代码? –

回答

0

这里是我如何解决此,由于上面的链接提供:

在我AppDelegate.h

补充:

- (NSMutableArray *)tabBarMutableArray; 

在我AppDelegate.m

加入:

- (NSMutableArray *)tabBarMutableArray; 
{ 
    UITabBarController *tabController   = (UITabBarController *)self.window.rootViewController; 
    NSMutableArray  *tabBarItemsMutableArray = [NSMutableArray new]; 

    UITabBar *tabBar = tabController.tabBar; 

    for (UIView *view in tabBar.subviews) 
    { 
     [tabBarItemsMutableArray addObject:view.description]; 
    } 

    return tabBarItemsMutableArray; 
} 

现在我可以与此任何地方访问该值:

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
NSLog(@"Array AppDelegate: %@", [appDelegate tabBarMutableArray]); 

结果:

"<_UITabBarBackgroundView: 0x145e19f70; frame = (0 0; 1024 56); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x1700359c0>>", 
"<UITabBarButton: 0x145e15950; frame = (254 1; 76 55); opaque = NO; layer = <CALayer: 0x17002a9a0>>", 
"<UITabBarButton: 0x145e19dd0; frame = (364 1; 76 55); opaque = NO; layer = <CALayer: 0x1700345c0>>", 
"<UITabBarButton: 0x145d0f8a0; frame = (474 1; 76 55); opaque = NO; layer = <CALayer: 0x17803cc60>>", 
"<UITabBarButton: 0x145e1a360; frame = (584 1; 76 55); opaque = NO; layer = <CALayer: 0x1700348e0>>", 
"<UITabBarButton: 0x145e1a940; frame = (694 1; 76 55); opaque = NO; layer = <CALayer: 0x170034c60>>", 
"<UIImageView: 0x145e1a090; frame = (0 -0.5; 1024 0.5); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x1700369e0>>" 
相关问题