直接上代码:
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.backgroundColor = [UIColor purpleColor];
[self.window makeKeyAndVisible];
UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 100, 100)] ;
[self.window addSubview:aView] ;
[aView release] ;
aView.backgroundColor = [UIColor cyanColor] ;
UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(25, 25, 100, 100)] ;
[aView addSubview:yellowView] ;
[yellowView release] ;
yellowView.backgroundColor = [UIColor yellowColor] ;
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(25, 25, 100, 100)] ;
[yellowView addSubview:blueView] ;
[blueView release] ;
blueView.backgroundColor = [UIColor blueColor] ;
NSLog( @"%@", NSStringFromCGRect(self.window.bounds) ) ;
UIView *anView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 300, 300)];
anView.backgroundColor = [UIColor redColor] ;
[self.window addSubview:anView] ;
[anView release] ;
NSLog( @"%@", NSStringFromCGPoint(anView.center) ) ;
anView.center = self.window.center ;
NSLog( @"%@", NSStringFromCGPoint(anView.center) ) ;
UIView *bView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)] ;
bView.backgroundColor = [UIColor orangeColor] ;
bView.center = anView.center ;
[anView addSubview:bView] ;
[bView release] ;
anView.bounds = CGRectMake(20, -20, 300, 300) ;
NSLog( @"%@", NSStringFromCGRect(anView.frame) ) ;
NSLog( @"%@", NSStringFromCGRect(bView.bounds) ) ;
UIView *greenView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 120, 120)] ;
greenView.backgroundColor = [UIColor greenColor] ;
[anView insertSubview:greenView belowSubview:bView] ;
[greenView release] ;
[anView bringSubviewToFront:greenView] ;
[anView sendSubviewToBack:greenView] ;
[greenView removeFromSuperview] ;
NSLog( @"%@", [anView superview] ) ;
NSLog( @"%@", [bView superview] ) ;
NSLog( @"%@", [anView subviews] ) ;
anView.alpha = 0.8 ;
anView.tag = 100 ;
UIView *getView = [self.window viewWithTag:100] ;
NSLog( @"%@", getView ) ;