热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

UIWindow方向问题(两个UIWindows和横向模式)

如何解决《UIWindow方向问题(两个UIWindows和横向模式)》经验,应该怎么办?

我知道这看起来像一个很大的问题,但并不是那么害怕阅读它.主要是我解释东西是如何工作的.

UIWindow我的应用程序中有两个s.第一个是默认情况下应用程序创建的主窗口.第二个被调用modalWindow,也在app delegate中创建.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.


    self.modalWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.modalWindow.windowLevel = UIWindowLevelStatusBar;

    //Other stuff I need
    //....

    return YES;
}

我的大多数应用程序只是纵向,但有一个视图控制器,用户可以切换到横向.我正在通过以下方式倾听景观变化:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];

这工作正常,并在orientationChanged方法中呈现横向视图控制器.一切都很顺利.如果我旋转回肖像,我orientationChanged再次被解雇,此时我解除了横向视图控制器.

现在让我们解释第二个窗口是如何发挥作用的.在横向模式下,有一个动作(只按一下按钮),在第二个窗口(the modalWindow)上显示一个新的视图控制器.好的,我们来解释一下.

app委托有两种方法,如下所示:

- (void)presentActivityOnModalWindow:(UIViewController *)viewController
{
    self.modalWindow.rootViewCOntroller= viewController;
    self.modalWindow.hidden = NO;
}

- (void)modalTransitionFinished:(NSNotification *)notif
{
    self.modalWindow.hidden = YES;
    self.modalWindow.rootViewCOntroller= nil;
}

我打电话给presentActivityOnModalWindow通过[[[UIApplication sharedApplication] delegate] performSelector....].我知道这不是最好的做法,但它运作正常.关于解雇我NSNotificationCenter用来发布关于解雇的通知.在其上呈现的视图控制器modalWindow仅支持纵向模式.它的返回YESshouldAutorotateUIInterfaceOrientationMaskPortraitsupportedInterfaceOrientations.

好的解释很多,但现在我们遇到了问题.当我旋转到横向时,弹出modalWindow,关闭模态窗口并旋转回到肖像我的主窗口仍处于横向模式,一切看起来都是灾难性的.

我尝试添加一个观察者既windowmodalWindow和登录的变化framebounds和这里的结果:

Did finish launching:
window frame {{0, 0}, {320, 568}}
window bounds {{0, 0}, {320, 568}}
modalWindow frame {{0, 0}, {320, 568}}
modalWindow bounds {{0, 0}, {320, 568}}

Rotate to landscape:
window frame {{0, 0}, {568, 320}}

Open activity in landscape:
modalWindow frame {{0, 0}, {320, 568}}
modalWindow frame {{0, 0}, {320, 568}}

Dismiss activity:
none


Rotate back to portrait:
none

因此,window当我们回到纵向模式时,我似乎没有回到正常的框架.如何解决这个问题?如果我需要提供更多细节,请随时提出.


推荐阅读
author-avatar
暴躁的玩具
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有