我有一个单身对象。有没有简单的方法来确定当前屏幕是否包含singlton方法中的导航栏?
单例是UIView的子类。它设计用于显示prorgess活动,例如,网络交换。它看起来像黑色矩形从顶部下降并在工作完成时隐藏。为什么单身?从任何代码处轻松调用它
以下代码段显示了活动单例的初始化,并在此处发布,只是为了更好地理解我的想法。
-(void) showUpdatingView:(NSString *) msg {
[self initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 44)];
activity = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
activity.frame = CGRectMake(5, 10, 22, 22);
labelView = [[[UILabel alloc] initWithFrame:CGRectMake(35, 10, [UIScreen mainScreen].bounds.size.width - 10, 22)] autorelease];
labelView.font = [UIFont boldSystemFontOfSize:12];
labelView.backgroundColor = [UIColor clearColor];
labelView.textColor = [UIColor whiteColor];
labelView.text = msg;
[self addSubview:activity];
[self addSubview:labelView];
self.backgroundColor = [UIColor blackColor];
self.alpha = 0.7;
}
活动可以通过
调用[[ActivitySingleton getInstance] showUpdatingView:@"Getting data."];
并非全部。 在AppDelegate对象中创建单例,并将视图添加到
inlineActivity = [[CHInlineActivityView alloc] initView];
[self.window.rootViewController.view addSubview:inlineActivity];
我知道这可能看起来很疯狂。但是当我在设计时,这在我看来是合理的
答案 0 :(得分:1)
如果你有一个在一个navigationController:
BOOL navHidden = self.window.rootViewController.navigationController.navigatonBarHidden;
如果你不这样做有点难......你可以查看窗口的子视图,看看你是否能找到UINavigationBar
id navbar = [self.window firstSubviewOfKind:[UINavigationBar class] withTag:NSNotFound];
BOOL navHidden = navbar == nil;
@implementation NSView (findSubview)
- (NSArray *)findSubviewsOfKind:(Class)kind withTag:(NSInteger)tag inView:(NSView*)v {
NSMutableArray *array = [NSMutableArray array];
if(kind==nil || [v isKindOfClass:kind]) {
if(tag==NSNotFound || v.tag==tag) {
[array addObject:v];
}
}
for (id subview in v.subviews) {
NSArray *vChild = [self findSubviewsOfKind:kind withTag:tag inView:subview];
[array addObjectsFromArray:vChild];
}
return array;
}
#pragma mark -
- (NSView *)firstSubviewOfKind:(Class)kind withTag:(NSInteger)tag {
NSArray *subviews = [self findSubviewsOfKind:kind withTag:tag inView:self];
return subviews.count ? subviews[0] : nil;
}
@end