考虑下面的自包含示例应用程序:
#import <UIKit/UIKit.h>@interface AppDelegate : UIResponder <UIApplicationDelegate>@property (strong,nonatomic) UIWindow *window;@end@implementation AppDelegate- (BOol)application:(UIApplication *)app dIDFinishLaunchingWithOptions:(NSDictionary *)opt{ // Content UILabel * aLbl = [[UILabel alloc] initWithFrame:CGRectMake(20,100,200,40)]; aLbl.text = @"In-call status bar issue"; UIVIEwController * aContent = [[UIVIEwController alloc] init]; aContent.Title = @"Title"; aContent.vIEw.backgroundcolor = UIcolor.whitecolor; [aContent.vIEw addSubvIEw:aLbl]; UINavigationController * aNav = [[UINavigationController alloc] initWithRootVIEwController:aContent]; // Parentmost vIEw controller containing the navigation vIEw controller UIVIEwController * aParent = [[UIVIEwController alloc] init]; [aParent.vIEw addSubvIEw:aNav.vIEw]; [aParent addChildVIEwController:aNav]; [aNav dIDMovetoParentVIEwController:aParent]; self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds]; self.window.rootVIEwController = aParent; [self.window makeKeyAndVisible]; return YES;}@endint main(int argc,char ** argv) { @autoreleasepool { return UIApplicationMain(argc,argv,nil,@"AppDelegate"); } }
重现问题的最简单方法是:
>启动iOS模拟器.
>按⌘Y打开通话中状态栏.状态栏将变为宽绿色.
>手动启动应用程序并等待导航控制器出现.
>再次按⌘Y可关闭通话中状态栏.
UI现在应该如下所示:
有谁知道如何解决这个问题?
解决方法 您正在将视图(导航控制器的视图)作为子视图添加到另一个视图(父视图控制器的视图),而不给它一个框架!这是你永远不应该做的事情.只需将这些行添加到您的代码中:
aNav.vIEw.frame = aParent.vIEw.bounds;aNav.vIEw.autoresizingMask = UIVIEwautoresizingFlexibleHeight | UIVIEwautoresizingFlexibleWIDth;
现在导航控制器的视图有一个框架,并相对于其超视图维护它.
总结以上是内存溢出为你收集整理的ios – 状态栏大小错误,包含UINavigationController全部内容,希望文章能够帮你解决ios – 状态栏大小错误,包含UINavigationController所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)