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

时间:2013-08-07 18:47:54

标签: objective-c cocoa-touch uiview nslayoutconstraint

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

继承我的代码:

-(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];

1 个答案:

答案 0 :(得分:0)

你试过UIView animateWithDuration:动画:方法吗?您可以将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移动到的位置。我不完全确定这是否是您正在寻找的,但似乎您正在寻找一种方法来为视图制作动画,所以这里有一个建议:)

希望这有帮助!

相关问题