【发布时间】:2012-05-22 18:23:19
【问题描述】:
我在 UIViewController 中,self.view 指向具有 300x480 框架的有效视图。
UIView *redView;
UIView *blueView;
//[[self view] setAutoresizingMask:YES]; //WRONG!
[[self view] setAutoresizesSubviews:YES];
[[self view] setClipsToBounds:YES];
redView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[redView setBackgroundColor:[UIColor redColor]];
[redView setAutoresizingMask:UIViewAutoresizingFlexibleLeftMargin];
[[self view] addSubview:redView];
blueView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
[blueView setBackgroundColor:[UIColor blueColor]];
[blueView setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin];
[[self view] addSubview:blueView];
我正在尝试使用这个 sn-p 代码
- 要将 200x200 红色视图与右边距对齐,
- 将 100x100 蓝色视图与左边距对齐;
但你所看到的结果与我所期望的相差甚远......
http://imageshack.us/photo/my-images/27/iossimulatorscreenshoto.png/
我已经阅读了所有关于自动调整掩码使用的苹果文档和谷歌搜索结果,但我仍然无法弄清楚为什么会发生这种情况。
有人可以向我解释发生了什么吗?
提前致谢。
【问题讨论】:
标签: ios uiview autoresizingmask