简体   繁体   中英

[self.window addSubview:[_viewController view]]; moving the view up in lower version of iphone

I am working on a universal application.I am using

self.window.rootViewController = self.SecondViewController

to load viewcontroller class in the AppDelegate method. This line of code is working fine for ios versions 4 and later but when i run it on my ios 3.1.3 it crashes.

So I replaced that code with [self.window addSubview:[SecondViewController view]] and it works fine but initially the view moves up(As in the screen shot) when we load the app for the first time.

So kindly help me overcome this issue thank you 在此处输入图片说明

The rootViewController property was introduced with iOS 4.0, that is the reason for the crash in iOS 3.1.3.

If you use [self.window addSubview:[SecondViewController view]] then it can happen that the view controllers view is not adjusted for the status bar. See Offset on UIWindow addSubview for a good explanation.

The solution is to assign the view's frame, in your case

self.SecondViewController.view.frame = [UIScreen mainScreen].applicationFrame;

before adding it as subview.

SecondViewController.view.frame = CGRectMake(0, 20, 320, 460);
[self.window addSubview:[SecondViewController view]]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM