我有三个 View :topView、middleView、bottomView。
当我点击 topView 中的按钮时,我想在 topView 和 middleView 之间插入 alpha View 。
但是middleView和bottomView已经在viewDidLoad调用方法[self.view addsubView:]定位了。
所以我必须更改 alpha View 下方的 middleView 和 bottomView...
所以我调用了方法“setFrame”,但是已经添加的 View 没有移动到我想要放置它们的位置。
所以我必须调用“removeFromSuperView”方法,但有一个大问题,即 middleView 和 bottomView 是主视图,其中包含多个 subview ...
我不知道如何解决这个问题,请帮助我!
! middleView和bottomView,他们只需要往下走,移动问题很简单。
****更新 我关于这个问题的代码如下:
authCodeView 是 alphaView
authCodeView = [[UIView alloc] initWithFrame:CGRectMake(0, topView.frame.size.height + 8, [UIScreen mainScreen].bounds.size.width, topView.frame.size.height)];
[authCodeView setBackgroundColor:[UIColor whiteColor]];
authCodeField = [[UITextField alloc] initWithFrame:CGRectMake(30, 0, authCodeView.frame.size.width - 30, authCodeView.frame.size.height)];
authCodeField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"인증번호 입력" attributes:@{NSForegroundColorAttributeName:tempGray}];
[authCodeView addSubview:authCodeField];
NSLog(@"%f",authCodeView.frame.origin.y+authCodeView.frame.size.height + 8);
[middleView setFrame:CGRectMake(100, authCodeView.frame.origin.y+authCodeView.frame.size.height + 8, [UIScreen mainScreen].bounds.size.width, 308.0f)];
[bottomView setFrame:CGRectMake(0, middleView.frame.origin.y+middleView.frame.size.height+8, [UIScreen mainScreen].bounds.size.width, bottomView.frame.size.height)];
[self.view addSubview:authCodeView];
[self.view addSubview:middleView];
[self.view addSubview:bottomView];
最佳答案
So I called method 'setFrame', but already added views didn't move to where i want to put them.
然后您将错误的矩形传递给 -setFrame:
。该方法会更改 View 的框架,即它在其父 View 的坐标系中的位置和大小。
So I have to call method 'removeFromSuperView' but there is a big problem that middleView and bottomView are the master views that has multiple subviews
您不需要为了更改其位置而删除 View 。如果你想将它添加到其他 View ,或者如果你不再需要它在父 View 中,你只需要删除它。也就是说,如果像 middleView
这样的 View 有 subview ,这不是问题——如果您将 middleView
从它的父 View 中删除,或者如果您更改 ,它们将与
的位置等middleView
一起使用>middleView
I don't know how to solve this problem, please help me!
寻求帮助时,您确实需要发布重现您要解决的问题的代码。
关于iOS)如何更改已添加 subview 的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32415216/