当视图动画为横向模式时,我试图更改 UIButton 的宽度。但是该方法被调用是因为我在那里设置了断点,但按钮的宽度没有改变。我将 IBOutlet 约束添加到按钮的宽度,名为:globalButtonWidthConstraint。
我当前的代码:
- (void)layoutSubviews {
[super layoutSubviews];
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
CGFloat screenH = screenSize.height;
CGFloat screenW = screenSize.width;
BOOL isLandscape = !(self.frame.size.width == (screenW*(screenW<screenH))+(screenH*(screenW>screenH)));
if (isLandscape) {
self.globalButtonWidthConstraint.constant = 100;
[self layoutIfNeeded];
} else {
self.globalButtonWidthConstraint.constant = 47;
[self layoutIfNeeded];
}
}
尝试更新“viewDidLayoutSubviews”中的约束常量。
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
// Update constraint constant
[self.view layoutSubviews];
}
这对我有用。
EDIT:确保没有其他约束与此宽度约束相冲突。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)