UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 20, 200, 200)];
v.tag = 100;
v.backgroundColor = [UIColor orangeColor];
[self.window addSubview:v];
[v release];
UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 50, 50)];
v1.backgroundColor = [UIColor blueColor];
//停靠模式 当父视图发生变化时 子视图也会发生相应的变化
v1.autoresizingMask = UIViewAutoresizingFlexibleHeight| UIViewAutoresizingFlexibleWidth;
[v addSubview:v1];
[v1 release];
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
b.frame = CGRectMake(0, 320, 100, 30);
[b setTitle:@"click" forState:UIControlStateNormal];
[b addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
[self.window addSubview:b];
return YES;
}
bool flag = YES;
-(void)click
{
UIView *v = [self.window viewWithTag:100];
if (flag) {
v.frame = CGRectMake(0, 20, 300, 300);
}else{
v.frame = CGRectMake(0, 20, 200, 200);
}
flag = !flag;
}