【发布时间】:2015-12-01 15:00:09
【问题描述】:
我有三个视图:topView、middleView、bottomView。
当我点击 topView 中的按钮时,我想在 topView 和 middleView 之间插入 alpha 视图。
但是 middleView 和 bottomView 已经通过在 viewDidLoad 调用方法 [self.view addsubView:] 定位。
所以我必须更改 alpha 视图下方的 middleView 和 bottomView...
所以我调用了方法“setFrame”,但是已经添加的视图没有移动到我想要放置它们的位置。
所以我必须调用方法 'removeFromSuperView' 但有一个大问题,middleView 和 bottomView 是主视图,其中有多个子视图...
我不知道如何解决这个问题,请帮助我!
! 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];
【问题讨论】:
-
请分享您的代码。
-
尝试删除
removeFromSuperView(也删除[self.view addSubview:middleView]; [self.view addSubview:bottomView];),并在middleView和bottomView的框架变化后调用setNeedDisplay -
是的,如果您使用带有一些约束的自动布局,那么您肯定不能像这样更新框架。您应该更新约束。
-
“它不起作用”是一个不充分的描述——您期望会发生什么,实际会发生什么?
-
尝试对您的约束做一些事情,更新框架将不起作用。不要删除并再次添加。
标签: ios uiview frame addsubview