[IOS development-18] What is the relationship between UIWindow and UIView? Isn't it important to upgrade UIWindow with xcode? Uiviewuiwindow

Source: Internet
Author: User

[IOS development-18] What is the relationship between UIWindow and UIView? Isn't it important to upgrade UIWindow with xcode? Uiviewuiwindow

(1) because the xcode version is different, the latest xcode does not provide blank documents that can be created at will in our old version (instead, it is purely a project with nothing to do with, yes, so we are built on a single MVC template. This example and all the previous Code are in ViewController. m, not in AppDelegate. m. Therefore, the parent view here is actually self. view rather than self. window, so the window we explain here is actually a child view of view in our template.


(2) In addition to setting the hidden attribute of the window object to NO, we also need to use self. view addSubView to load it so that our window can be displayed.


(3) In addition, we can see that some attribute operations on the window shelf, such as UIWindowLevelStatusBar, do not actually work, because the window level is defined by the parent view self. the order in which views are loaded is determined, and other views are overwritten on the loaded view.


(4) In the future, we can only use the UIWindow view as a sub-view of the UIView and layout it in the app? Maybe this is our guess for the moment. Let's move on.


(5) In the past, we all mentioned that it is a window. If there is a player in it, the player is also a window loaded on it. Now we all seem to use view to talk about things. There are few answers to how to gradually change from UIWindow to UIView. In some cases, it is estimated that UIWindow is quite useful.


# Import "ViewController. h "@ interface ViewController () @ end @ implementation ViewController-(void) viewDidLoad {// UIWindow * window1 = [[UIWindow alloc] init]; UIWindow * window2 = [[UIWindow alloc] init]; UIWindow * window3 = [[UIWindow alloc] init]; window1.frame = CGRectMake (0, 0,300,300); window1.backgroundColor = [UIColor grayColor]; window2.frame = CGRectMake (0, 0,200,400); window2.backgroundColor = [UIColor GreenColor]; window3.frame = CGRectMake (0, 0,250,200); window3.backgroundColor = [UIColor redColor]; // The window object is hidden by default. You need to set window1.hidden = NO; window2.hidden = NO; window3.hidden = NO; // set the level of the window view, which is invalid. Normally, the status bar is Normal. Generally, the status bar is the UIWindowLevelStatusBar layer. It is set to overwrite the status bar with regret. The level of UIWindowLevelAlert is the highest, but this is invalid because it is loaded in self. view, so the loading sequence is determined. Other settings are invalid. window2.windowLevel = UIWindowLevelAlert; window3.windowLevel = UIWindowLevelStatusBar, other uiwindows are their subviews [self. view addSubview: window1]; [self. view addSubview: window2]; [self. view addSubview: window3]; [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib .} -(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .} @ end

In AppDelegate, we try the following:

@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    UIWindow *window4=[[UIWindow alloc]init];    window4.frame=CGRectMake(0, 0, 100, 80);    window4.backgroundColor=[UIColor purpleColor];    window4.hidden=NO;    window4.windowLevel=UIWindowLevelStatusBar;    [self.window addSubview:window4];    // Override point for customization after application launch.    return YES;}

Screenshot:



How do I manually add windows and views when creating an empty project in Xcode for ios development?

Your delegate has generated a window, so you do not need mainWindow. xib. You have created mainWindow. the effect of xib is the same as that of using code to generate a window. If you want to generate a view, you can directly add the class of UIViewController, and check whether the nib file is included in your selection, then, generate the UIViewController instance in the delegate, and then directly [self. window addSubview: viewController. view.
Of course, you can also manually create an empty nib, specify the class it is, and then add the corresponding controls.
Hope to help you.

Why can't xcode find the window based application? My machine is the lion system, and the development tool is the latest in 421.

Xcode4.2 does not have a template for the window based application project. Therefore, you cannot create a new project. You can create an empty application. Then everything becomes the same. I think xcode4.0 and above are rarely used to xib files! Hope to help you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.