一个View作为所有ViewController中的Status View
One View as StatusView in all ViewControler
我的导航栏下方有一个小视图,其中包含信息。当我切换到它们时,我希望在我的另外三个 viewcontroller 中看到相同的信息视图。我需要每次都创建一个新视图吗?
非常感谢!
更新:解决方案是[self.navigationController.view insertSubview:pullDownView atIndex:1];请参阅下面的 post
不,将视图作为子视图添加到您的 window,并确保正确放置它。使用更改 window 维度的事件测试您的代码(例如,从调用切换到应用程序)。
如果您正在使用导航控制器或任何其他视图控制器容器,最好将您的视图作为子视图添加到容器中,尽管我自己没有亲自尝试过,它可能不起作用或涉及太多许多 hacks/work 周围才能正常工作。
您可以对 UIViewController 进行扩展。该扩展 class 将具有在顶部添加视图的功能。
因此,无论您想在哪个视图中添加子视图,您只需调用该函数即可。
请参阅下文 link 了解如何创建类别扩展,
http://iosdevelopertips.com/objective-c/categories.html
您可以为 UIViewcontroller 创建相同的内容。
当您定义了 UINavigationController
或任何第一次在 AppDelegate
或其他地方加载的容器控制器时,那时以编程方式将您的视图添加为 navigationcontoller.view 的子视图或导航栏下的容器控制器。在这里你必须确保你的子视图的完美位置。
无需在每个视图中添加视图 controller.we 可以根据需要进行自定义 controllers.Just 将视图作为子视图添加到 window.Try 此解决方案可能对您有所帮助。
//在appDelegate.h
@property (strong,nonatomic) UIView *bottomView;
//在appDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, 65, 320, 50)];
_bottomView.backgroundColor = [UIColor blueColor];
_bottomView.hidden = YES;
[self.window addSubview:_bottomView];
}
//在viewcontroller1.m
#import "AppDelegate.h"
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *aDelegate = [[UIApplication sharedApplication] delegate];
aDelegate.bottomView.hidden = NO;
}
//在viewcontroller2.m
#import "AppDelegate.h"
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *aDelegate = [[UIApplication sharedApplication] delegate];
aDelegate.bottomView.hidden = NO;
}
//在viewcontroller3.m
#import "AppDelegate.h"
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *aDelegate = [[UIApplication sharedApplication] delegate];
aDelegate.bottomView.hidden = NO;
}
//在其他视图控制器中
#import "AppDelegate.h"
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *aDelegate = [[UIApplication sharedApplication] delegate];
aDelegate.bottomView.hidden = YES;
}
我的导航栏下方有一个小视图,其中包含信息。当我切换到它们时,我希望在我的另外三个 viewcontroller 中看到相同的信息视图。我需要每次都创建一个新视图吗?
非常感谢!
更新:解决方案是[self.navigationController.view insertSubview:pullDownView atIndex:1];请参阅下面的 post
不,将视图作为子视图添加到您的 window,并确保正确放置它。使用更改 window 维度的事件测试您的代码(例如,从调用切换到应用程序)。
如果您正在使用导航控制器或任何其他视图控制器容器,最好将您的视图作为子视图添加到容器中,尽管我自己没有亲自尝试过,它可能不起作用或涉及太多许多 hacks/work 周围才能正常工作。
您可以对 UIViewController 进行扩展。该扩展 class 将具有在顶部添加视图的功能。
因此,无论您想在哪个视图中添加子视图,您只需调用该函数即可。
请参阅下文 link 了解如何创建类别扩展, http://iosdevelopertips.com/objective-c/categories.html
您可以为 UIViewcontroller 创建相同的内容。
当您定义了 UINavigationController
或任何第一次在 AppDelegate
或其他地方加载的容器控制器时,那时以编程方式将您的视图添加为 navigationcontoller.view 的子视图或导航栏下的容器控制器。在这里你必须确保你的子视图的完美位置。
无需在每个视图中添加视图 controller.we 可以根据需要进行自定义 controllers.Just 将视图作为子视图添加到 window.Try 此解决方案可能对您有所帮助。
//在appDelegate.h
@property (strong,nonatomic) UIView *bottomView;
//在appDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
_bottomView = [[UIView alloc]initWithFrame:CGRectMake(0, 65, 320, 50)];
_bottomView.backgroundColor = [UIColor blueColor];
_bottomView.hidden = YES;
[self.window addSubview:_bottomView];
}
//在viewcontroller1.m
#import "AppDelegate.h"
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *aDelegate = [[UIApplication sharedApplication] delegate];
aDelegate.bottomView.hidden = NO;
}
//在viewcontroller2.m
#import "AppDelegate.h"
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *aDelegate = [[UIApplication sharedApplication] delegate];
aDelegate.bottomView.hidden = NO;
}
//在viewcontroller3.m
#import "AppDelegate.h"
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *aDelegate = [[UIApplication sharedApplication] delegate];
aDelegate.bottomView.hidden = NO;
}
//在其他视图控制器中
#import "AppDelegate.h"
- (void)viewDidLoad {
[super viewDidLoad];
AppDelegate *aDelegate = [[UIApplication sharedApplication] delegate];
aDelegate.bottomView.hidden = YES;
}