
通过向右旋转一次获得景观.
我创建和显示UIWindow的代码片段如下:
UIWindow *window=[UIApplication sharedApplication].keyWindow;self.progressWindow = [[UIWindow alloc] initWithFrame:window.frame];self.progressWindow.backgroundcolor = [UIcolor colorWithRed:0.0f green:0.0f blue:0.0f Alpha:0.5f];self.progressWindow.windowLevel = UIWindowLevelAlert;/* some other code to create the subvIEws */[self.progressWindow makeKeyAndVisible];
此问题仅发生在iOS 8上.
解决方法 据我所知,当方向发生变化时,新创建的UIWindow不会自动旋转.我不知道这是iOS 8的新功能还是它是一个BUG,但我能够通过以下代码克服这个问题:UIWindow *window=[UIApplication sharedApplication].keyWindow;self.progressWindow = [[UIWindow alloc] initWithFrame:window.frame];self.progressWindow.backgroundcolor = [UIcolor colorWithRed:0.0f green:0.0f blue:0.0f Alpha:0.5f];self.progressWindow.windowLevel = UIWindowLevelAlert;/* some other code to create the subvIEws */[self handleOrIEntationChange];[self.progressWindow makeKeyAndVisible];[[NSNotificationCenter defaultCenter] addobserver:self selector:@selector(handleOrIEntationChange) name:UIApplicationDIDChangeStatusbarFrameNotification object:nil];
handleOrIEntationChange的实现如下:
#define degreesToradians(degrees) (degrees * M_PI / 180)- (voID)handleOrIEntationChange{ if (self.progressWindow) { // rotate the UIWindow manually UIInterfaceOrIEntation orIEntation = [[UIApplication sharedApplication] statusbarOrIEntation]; [self.progressWindow settransform:[self transformForOrIEntation:orIEntation]]; // resize the UIWindow according to the new screen size if ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]) { // iOS 8 CGRect screenRect = [UIScreen mainScreen].nativeBounds; CGRect progressWindowFrame = self.progressWindow.frame; progressWindowFrame.origin.x = 0; progressWindowFrame.origin.y = 0; progressWindowFrame.size.wIDth = screenRect.size.wIDth / [UIScreen mainScreen].nativeScale; progressWindowFrame.size.height = screenRect.size.height / [UIScreen mainScreen].nativeScale; self.progressWindow.frame = progressWindowFrame; } else { // iOs 7 or below CGRect screenRect = [UIScreen mainScreen].bounds; CGRect progressWindowFrame = self.progressWindow.frame; progressWindowFrame.origin.x = 0; progressWindowFrame.origin.y = 0; progressWindowFrame.size.wIDth = screenRect.size.wIDth; progressWindowFrame.size.height = screenRect.size.height; self.progressWindow.frame = progressWindowFrame; } }}- (CGAffinetransform)transformForOrIEntation:(UIInterfaceOrIEntation)orIEntation { switch (orIEntation) { case UIInterfaceOrIEntationLandscapeleft: return CGAffinetransformMakeRotation(-degreesToradians(90)); case UIInterfaceOrIEntationLandscapeRight: return CGAffinetransformMakeRotation(degreesToradians(90)); case UIInterfaceOrIEntationPortraitUpsIDeDown: return CGAffinetransformMakeRotation(degreesToradians(180)); case UIInterfaceOrIEntationPortrait: default: return CGAffinetransformMakeRotation(degreesToradians(0)); }} 我从this问题的接受答案中得到了这个想法.
总结以上是内存溢出为你收集整理的ios – 在横向上打开应用程序时,新创建的UIWindow是横向的全部内容,希望文章能够帮你解决ios – 在横向上打开应用程序时,新创建的UIWindow是横向的所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)