Objective c 隐藏另一个视图时调整视图大小

Objective c 隐藏另一个视图时调整视图大小,objective-c,cocoa-touch,uiview,nslayoutconstraint,Objective C,Cocoa Touch,Uiview,Nslayoutconstraint,我在iPhone屏幕上有两个视图,一个在另一个上方(deviceWebView上方的mediaControls)。当我隐藏顶视图时,我希望底视图占据整个屏幕,当我显示顶视图时,我希望底视图再次调整大小,使其位于顶视图之下。这看起来很简单,但我有麻烦。 我只尝试了隐藏视图以及调整布局约束,如下所示 这是我的密码: -(void)hideVideoButtons{ self.mediaControls.hidden = YES; [self.view removeConstraint

我在iPhone屏幕上有两个视图,一个在另一个上方(deviceWebView上方的mediaControls)。当我隐藏顶视图时,我希望底视图占据整个屏幕,当我显示顶视图时,我希望底视图再次调整大小,使其位于顶视图之下。这看起来很简单,但我有麻烦。 我只尝试了隐藏视图以及调整布局约束,如下所示

这是我的密码:

-(void)hideVideoButtons{
    self.mediaControls.hidden = YES;
    [self.view removeConstraint:self.deviceLayoutConstraint];
    [self.deviceWebView setNeedsDisplay];
}
-(void)showVideoButtons{
    self.mediaControls.hidden=NO;
    self.deviceLayoutConstraint = [NSLayoutConstraint constraintWithItem:self.deviceWebView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.mediaControls attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
    [self.view addConstraint:self.deviceLayoutConstraint];

您是否尝试过UIView animateWithDuration:animations:方法?可以将UIView设置为任意位置的动画,可以调整其大小,等等

[UIView animateWithDuration:1.0 animations:^{
   // moving the device web view 
   self.deviceWebView.transform = CGAffineTransformMakeTranslation(xVar, yVar);
   // moving the other view
   otherView.transform = CGAffineTransformMakeTranslation(xVar, yVar);
}];
xVar和yVar不是正在设置的变量。它们只是展示了该方法的用法。将它们替换为要将视图的x和y移动到的屏幕的x和y位置。我不完全确定这是否是您要寻找的,但似乎您正在寻找一种方法来设置视图的动画,因此这里有一个建议:)


希望这有帮助

我不太愿意使用x坐标和y坐标,因为这对任何尺寸的屏幕都不起作用(如iPhone4和iPhone5)