Maj*_*ter 6 objective-c uiviewcontroller uiwindow ios ios8
我知道这看起来像一个很大的问题,但并不是那么害怕阅读它.主要是我解释东西是如何工作的.
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;
}
Run Code Online (Sandbox Code Playgroud)
我的大多数应用程序只是纵向,但有一个视图控制器,用户可以切换到横向.我正在通过以下方式倾听景观变化:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
Run Code Online (Sandbox Code Playgroud)
这工作正常,并在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;
}
Run Code Online (Sandbox Code Playgroud)
我打电话给presentActivityOnModalWindow通过[[[UIApplication sharedApplication] delegate] performSelector....].我知道这不是最好的做法,但它运作正常.关于解雇我NSNotificationCenter用来发布关于解雇的通知.在其上呈现的视图控制器modalWindow仅支持纵向模式.它的返回YES中shouldAutorotate和UIInterfaceOrientationMaskPortrait的supportedInterfaceOrientations.
好的解释很多,但现在我们遇到了问题.当我旋转到横向时,弹出modalWindow,关闭模态窗口并旋转回到肖像我的主窗口仍处于横向模式,一切看起来都是灾难性的.
我尝试添加一个观察者既window与modalWindow和登录的变化frame和bounds和这里的结果:
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
Run Code Online (Sandbox Code Playgroud)
因此,window当我们回到纵向模式时,我似乎没有回到正常的框架.如何解决这个问题?如果我需要提供更多细节,请随时提出.
系统只会处理您的轮换keyWindow. 如果您有其他窗口,则必须自己处理旋转。
我还认为模态控制器是可行的方法。但如果您确实想处理旋转,请查看其他“自定义窗口”库如何处理旋转。警报视图就是一个很好的例子:
\n\nhttps://github.com/search?o=desc&q=uialertview&s=stars&type=Repositories&utf8= \xe2\x9c\x93
\n| 归档时间: |
|
| 查看次数: |
2735 次 |
| 最近记录: |