窗口的旋转而不是 ViewController
首先我是一个n00b。经过长时间的尝试和研究,我决定寻求一些外部帮助。 我的项目: 我为儿童制作了一本书,但被拒绝了,因为它只允许纵向。 看来苹果也想要颠倒过来。 在我的 appdelegate 中,我切换 ViewController(我的书的页面),旋转起作用。 但在页面后面,我有来自应用程序代理的窗口,页面正在旋转,但不是我的窗口/背景。 在我的委托中,我如何以及在何处可以(允许)纵向和上下颠倒旋转我的窗口? 这是我的应用程序代表:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIImage *bg = [UIImage imageNamed:@"t2.jpg"];
UIImageView *tisch = [[UIImageView alloc] initWithImage:bg];
tisch.frame = CGRectMake(0, 0, 768, 1024);
[window addSubview:tisch];
[tisch release];
[self addButtonNext];
[self initAnimation];
[self animieren:self.animation];
[self playNavigation];
[self addButtonStop];
[self addButtonPlay];
[window makeKeyAndVisible];
return YES;
}
有什么想法吗? 如果有人能帮助我,那就太酷了! 预先感谢普朗基
First of all i am a n00b. After long time of trying and research i decided to get some external help.
My Project:
i made a book for children, but it was rejected because it only allowed portrait orientation.
it seams apple wants upside-down as well.
in my appdelegate i switch the ViewControllers (Pages of my Book), there the rotation works.
But behind the Pages i have the window from my appdelegate, the pages are rotating but not my window/background.
How and where in my delegate can i (allow) rotate my window in portrait and upside-down?
Here my appdelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIImage *bg = [UIImage imageNamed:@"t2.jpg"];
UIImageView *tisch = [[UIImageView alloc] initWithImage:bg];
tisch.frame = CGRectMake(0, 0, 768, 1024);
[window addSubview:tisch];
[tisch release];
[self addButtonNext];
[self initAnimation];
[self animieren:self.animation];
[self playNavigation];
[self addButtonStop];
[self addButtonPlay];
[window makeKeyAndVisible];
return YES;
}
Any ideas?
It would be really cool if anyone could help me!
Thanks in advance Planky
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,当你说“看来苹果也想要颠倒过来”时,这是非常令人惊讶的。大多数 iOS 应用程序明确不支持颠倒方向,因为这通常会带来糟糕的用户体验。它们仅支持纵向和左/右横向。
接下来,不要将子视图直接添加到 win
dow
中。这几乎总是错误的,并且绕过了内置的轮换逻辑(正如您所发现的)。只需使用UIViewController
。这就是它的用途。您可以(尽管通常不应该)向window.rootViewController.view
添加内容,但这实际上仅适用于特殊问题(例如跨对等视图的拖放)。只需使用视图控制器即可。它将立即解决您 90% 的问题。不是每个页面有一个视图控制器,而是只有一个 PageViewController 来更改它显示的页面。然后,PageViewController 可以将所有这些额外的 UI 元素放入视图中。
First, when you say "it seams apple wants upside-down as well" this is very surprising. Most iOS applications explicitly do not support upside-down orientation since it is often a poor user experience. They only support portrait and left/right landscape.
Next, do not add subviews directly to the win
dow
. This is almost always wrong and bypasses the built-in rotation logic (as you've discovered). Just use aUIViewController
. That's what it's for. You can (though you generally shouldn't) add things to thewindow.rootViewController.view
, but this is really only for specialized problems (like drag-and-drop across peer views). Just use a view controller. It will solve 90% of your problems out of the box.Rather than having a single view controller per page, just have a single PageViewController that changes which Page it displays. The PageViewController can then put all these extra UI elements into the view.