【发布时间】:2014-02-15 20:31:18
【问题描述】:
我的目标是在我的教程中启动应用程序时为我的每个 UITabBarbuttons 显示一个 UIPopover...我正在执行以下操作:
如何从UIView *tabView = [[appDelegate tabBarMutableArray] objectAtIndex:1]; 中提取框架,这是第一个 UITabBarButton。
Array AppDelegate: <UITabBarButton: 0x145d06a70; frame = (254 1; 76 55); opaque = NO; layer = <CALayer: 0x17802c160>>
现在我手动输入 254,712,76,55 的 GCRect。我通过减去 768 - 56 得到 712,并且弹出框处于完美位置。但我宁愿通过检索值来进行计算...那么如何提取上述结果的frame = (254 1; 76 55) 部分?
frame = CGRectMake(254,712,76,55);
AppDelegate.h
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
- (NSMutableArray *)tabBarMutableArray;
@end
AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
#define debug 1
- (NSMutableArray *)tabBarMutableArray;
{
if (debug==1) {
NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));
}
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;
}
viewcontroller.m
-(void)showHomeTabBarPopOver
{
if (debug==1) {
NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));
}
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
CGRect frame = CGRectZero;
NSLog(@"%@", [appDelegate tabBarMutableArray]);
NSLog(@"Array AppDelegate: %@", [[appDelegate tabBarMutableArray] objectAtIndex:1]);
UIView *tabView = [[appDelegate tabBarMutableArray] objectAtIndex:1];
NSLog(@"tabView %@", [tabView valueForKey:@"frame"]);
// frame = tabView.frame;
NSLog(@"frame %@", CGRectCreateDictionaryRepresentation(self.view.frame));
frame = CGRectMake(254,712,76,55); //254,712,76,55
[_getStartedPopover presentPopoverFromRect:frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
结果
2014-02-07 14:35:47.940 mCC HD[1964:60b] (
"<_UITabBarBackgroundView: 0x145d0cb30; frame = (0 0; 1024 56); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x17802db00>>",
"<UITabBarButton: 0x145d06a70; frame = (254 1; 76 55); opaque = NO; layer = <CALayer: 0x17802c160>>",
"<UITabBarButton: 0x145e2e360; frame = (364 1; 76 55); opaque = NO; layer = <CALayer: 0x17003c2e0>>",
"<UITabBarButton: 0x145d0a060; frame = (474 1; 76 55); opaque = NO; layer = <CALayer: 0x17802c6a0>>",
"<UITabBarButton: 0x145d0a640; frame = (584 1; 76 55); opaque = NO; layer = <CALayer: 0x17802ca20>>",
"<UITabBarButton: 0x145d0ae60; frame = (694 1; 76 55); opaque = NO; layer = <CALayer: 0x17802cda0>>",
"<UIImageView: 0x145d0edd0; frame = (0 -0.5; 1024 0.5); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x17802f0a0>>"
)
2014-02-07 14:35:47.940 mCC HD[1964:60b] Running AppDelegate 'tabBarMutableArray'
2014-02-07 14:35:47.941 mCC HD[1964:60b] Array AppDelegate: <UITabBarButton: 0x145d06a70; frame = (254 1; 76 55); opaque = NO; layer = <CALayer: 0x17802c160>>
2014-02-07 14:35:47.943 mCC HD[1964:60b] frame {
Height = 768;
Width = 1024;
X = 0;
Y = 0;
提前谢谢...
-保罗斯
【问题讨论】:
标签: ios7 uipopovercontroller uitabbaritem cgrect