我以编程方式在屏幕上放置了带有帧(0、100、50、50)的UIView,并将其autoresizingMask设置为UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin,当我开始旋转屏幕时,由于某种原因,视图会停留在右边缘。如果我设置视框(20、100、50、50),则一切正常。
我究竟做错了什么?
样例代码:
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *cell = [[UIView alloc] initWithFrame:CGRectMake(0, 100, 50, 50)];
cell.backgroundColor = [UIColor blackColor];
cell.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleLeftMargin;
[self.view addSubview:cell];
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAll;
}
轮换之前:
---------------------------
| |
|===== |
|| | |
|===== |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
-----------------------------
| o |
---------------------------
旋转后,一切正常:
------------------------------------------------
| | |
| =====| |
| | || |
| =====| |
| | |
| | o |
| | |
| | |
| | |
| | |
| | |
------------------------------------------------
---------------------------
| |
| =====|
| | ||
| =====|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
-----------------------------
| o |
---------------------------
如果我改变
UIView * cell = [[UIView alloc] initWithFrame:CGRectMake(0,100,50,50)];
到
UIView * cell = [[UIView alloc] initWithFrame:CGRectMake(20,100,50,50)];
轮换之前:
---------------------------
| |
| ===== |
| | | |
| ===== |
| |
| |
| |
| |
| |
| |
| |
| |
| |
-----------------------------
| o |
---------------------------
旋转后,一切正常:
-------------------------------------------------
| | |
| ===== | |
| | | | |
| ===== | |
| | |
| | o |
| | |
| | |
| | |
| | |
| | |
-------------------------------------------------
---------------------------
| |
| ===== |
| | | |
| ===== |
| |
| |
| |
| |
| |
| |
| |
| |
| |
-----------------------------
| o |
---------------------------
试试这个:
cell.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleBottomMargin;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句