iPad - UISplitViewController - 背景颜色

发布于 2024-10-14 16:45:32 字数 1089 浏览 2 评论 0原文

我有一个 UISplitViewController 设置,但由于某种原因,背景只有旋转一次后才会固定。

我使用 IB 设置分割视图并将详细视图设置为 IPadDetailViewController。在其中我有以下内容:

- (void)loadView {
    [super loadView];

    self.view.backgroundColor = [UIColor greenColor];

    toolbar = [[UIToolbar alloc] initWithFrame:CGRectZero];
    toolbar.barStyle = UIBarStyleDefault;
    [toolbar sizeToFit];
    [self.view addSubview:toolbar];

}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    self.view.backgroundColor = [UIColor orangeColor];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"it is in landscape!");
        self.view.backgroundColor = [UIColor grayColor]];       
    }
    else {
        NSLog(@"it is in portrait!");
        self.view.backgroundColor = [UIColor blueColor];

    }   
}

虽然代码运行并且我的工具栏位于顶部,但视图仍然是黑色的(它以模拟器的横向方式开始)。

有什么想法吗?

I have a UISplitViewController setup, but for some reason the background isn't taking hold until you've rotated it once.

I use IB to setup the split view and set the detail view to be IPadDetailViewController. Inside that I have the following:

- (void)loadView {
    [super loadView];

    self.view.backgroundColor = [UIColor greenColor];

    toolbar = [[UIToolbar alloc] initWithFrame:CGRectZero];
    toolbar.barStyle = UIBarStyleDefault;
    [toolbar sizeToFit];
    [self.view addSubview:toolbar];

}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];

    self.view.backgroundColor = [UIColor orangeColor];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
        self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
        NSLog(@"it is in landscape!");
        self.view.backgroundColor = [UIColor grayColor]];       
    }
    else {
        NSLog(@"it is in portrait!");
        self.view.backgroundColor = [UIColor blueColor];

    }   
}

Though the code gets run and my toolbar gets place at the top, the view remains black (it starts in landscape for the Simulator).

Any ideas why?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧夏天 2024-10-21 16:45:32

尝试在 iPadDetailViewController 中的 awakeFromNib 方法中设置背景颜色

try setting the background color in awakeFromNib method in your iPadDetailViewController

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文