窗口中的 addsubview 问题
我想在我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,伙计们,我自己修好了。
我添加了一个 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!
您确定已为第二个视图启用横向模式吗?
Are you sure landscape mode is enabled for second view?