我在 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];
使用这段代码我正在尝试
- 要将 200x200 红色视图与右边距对齐,
- 将 100x100 蓝色视图与左边距对齐;
但如你所见,结果远非我所期待的……
http://imageshack.us/photo/my-images/27/iossimulatorscreenshoto.png/
我已经阅读了所有关于自动调整掩码使用的苹果文档和谷歌结果,但我仍然无法弄清楚为什么会发生这种情况。
有人可以向我解释发生了什么吗?
提前致谢。