【发布时间】:2024-01-05 23:45:01
【问题描述】:
我有如下视图:
当我尝试在 CGSizeZero 框架中折叠 schedinaContView 时,它仅在 schedina 的子视图为空时才有效。
这是我的代码:
-(void)prepareFloatSchedina
{
schedinaVC = [[SchedinaViewController alloc] initWithNibName:@"SchedinaViewController" bundle:nil];
schedinaVC.view.frame = self.schedina.frame;
[self.schedina addSubview: schedinaVC.view];
schedinaExpandedSize = _schedinaContView.frame.size;
CGRect frame = [UIUtilCollection frameInSuperFrame:self.view.frame atCornerWithSize:schedinaCompressedSize];
_schedinaContView.frame = frame;
NSLog(NSStringFromCGRect(_schedinaContView.frame));
UIButton *bottone = [[UIButton alloc] initWithFrame:CGRectMake(0.0, 0.0, 20.0, 20.0)];
[bottone setTitle:@"Ciao" forState:UIControlStateNormal];
[self.schedina addSubview:bottone];
}
这是 NSLog 的结果:
{{1004, 748}, {0, 0}}
但是 _schedinaContView 仍然存在于视图中!
所以,如果我删除 UIButton,它会完美运行。这就是为什么?
已解决:
我解决了将方法[translatesAutoresizingMaskIntoConstraints:] 的参数设置为YES
然后我在焦点视图上停用了 NSLayoutConstraint,并在我尝试打开视图时重新激活。
[_schedinaContView setTranslatesAutoresizingMaskIntoConstraints:YES];
_verticalSpace.active = NO;
【问题讨论】:
标签: ios objective-c autolayout frame