不疯不成魔

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(30, 30, 200, 200)];
    yellowView.backgroundColor = [UIColor yellowColor];
    [self.window addSubview:yellowView];
    UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)];
    redView.backgroundColor = [UIColor redColor];
    //[self.window addSubview:redView];
    
    [yellowView addSubview:redView];
一开始RedView在yellowView的中间

 

第一步设置
yellowView.bounds = CGRectMake(0, 0, 200, 200);
//这表示yellowView在屏幕中的位置和大小不变,yellowView的左上角的相对于与其子视图为(0,0)
第二步设置
yellowView.bounds = CGRectMake(50, 50, 200, 200);
这表示yellowView在屏幕中的位置和大小不变,yellowView的左上角的相对于与其子视图为(50,50)
//位置如下,黄色视图的位置始终不变,bounds的x,y改变的是子视图相对于它的位置

posted on 2015-09-19 11:08  不疯不成魔  阅读(190)  评论(0编辑  收藏  举报