窗口中的 addsubview 问题

发布于 2024-09-18 11:13:06 字数 1237 浏览 10 评论 0原文

我想在我的 AppDelegateController 中添加两个子视图到窗口。均处于横向模式。当我添加第一个视图时,它处于横向模式(这很好),但是当添加第二个视图时,它会自动处于纵向模式。有什么建议吗?

谢谢+问候

,在我的AppDelegate.m

[window addSubview:viewController.view];

CGRect frame = startviewController.view.frame;

frame.origin.x = 400;
frame.origin.y = 0;

startviewController.view.frame = frame;

[window addSubview:startviewController.view];

,在我的AppDelegate.h中,

@class LearnShiftViewController;
@class StartViewController;

@interface LearnShiftAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    LearnShiftViewController *viewController;
  StartViewController *startviewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet LearnShiftViewController *viewController;
@property (nonatomic, retain) IBOutlet StartViewController *startviewController;

在我的MainWindow.xib中,我添加了我想要添加的两个视图控制器作为子视图!

我使它们成为横向的方法是将其放入两个视图控制器的 shouldAutorotateToInterfaceOrientation 方法中:

return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);

并在 InterfaceBuilder 中将方向设置为横向。

i want to add two subviews to window in my AppDelegateController. both in landscape mode. when i add the first view, it is in landscape (that's fine), but when adding the second, it is automatically in portrait mode. any advice?

thanks + regards

that's in my AppDelegate.m

[window addSubview:viewController.view];

CGRect frame = startviewController.view.frame;

frame.origin.x = 400;
frame.origin.y = 0;

startviewController.view.frame = frame;

[window addSubview:startviewController.view];

that's in my AppDelegate.h

@class LearnShiftViewController;
@class StartViewController;

@interface LearnShiftAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    LearnShiftViewController *viewController;
  StartViewController *startviewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet LearnShiftViewController *viewController;
@property (nonatomic, retain) IBOutlet StartViewController *startviewController;

In my MainWindow.xib I added both view controllers I want to add as subviews!

My way to make them landscape is putting this in the shouldAutorotateToInterfaceOrientation method of both view controllers:

return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);

and set the orientation to Landscape in InterfaceBuilder.

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

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

发布评论

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

评论(2

甜心小果奶 2024-09-25 11:13:06

好吧,伙计们,我自己修好了。

我添加了一个 DummyViewController,在其中添加了两个子视图。因此,只有一个视图被添加到窗口中。现在工作完美:)但无论如何还是谢谢!

okay guys, i fixed it myself.

i added a DummyViewController, where I add the two SubViews. So only one view is added to the window. Works flawlessly now :) But thanks anyway!

望笑 2024-09-25 11:13:06

您确定已为第二个视图启用横向模式吗?

Are you sure landscape mode is enabled for second view?

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