gpt4 book ai didi

ios - Autoresizingmask 无法正常工作

转载 作者:行者123 更新时间:2023-12-01 16:39:03 25 4
gpt4 key购买 nike

我以编程方式在屏幕上放置了一个带有框架(0、100、50、50)的 UIView,并将其 autoresizingMask 设置为 UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin 并且当我开始旋转屏幕时,由于某种原因, View 会停留在右边缘。如果我设置 View 框架(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;

关于ios - Autoresizingmask 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25948610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com