首页 > 解决方案 > 目标 C:如何在隐藏 UIView 之前使 UIScrollView 结束?

问题描述

我希望能够使 UIScrollView 在隐藏元素(UIView)之前结束。我无法从场景中删除 modeView,因为该功能当前被禁用,但将来可能会启用,一旦必须启用该功能,就必须显示 UIView (modeView)。

在此处输入图像描述

当 UIVIew *modeView 被隐藏时,我尝试了以下方法来降低高度,但是 UIScrollView 仍然没有在正确的位置结束。

在此处输入图像描述

以下是代码:

modeView.hidden = YES;
    
int contentViewHeight = 1000;
    
NSLog(@"modeView Height: %f", modeView.frame.size.height);
    
if(modeView.hidden == YES) {
   contentViewHeight = contentViewHeight - modeView.frame.size.height;
}
else {
   contentViewHeight = 1000;
}

contentView.frame = CGRectMake(0, 0, [Helper getScreenWidth], contentViewHeight);
[scrollView addSubview:contentView];
scrollView.contentSize = CGSizeMake([Helper getScreenWidth], contentViewHeight);

任何帮助将非常感激!谢谢!

标签: iosobjective-c

解决方案


您不会根据条件更改 scrollView 高度。它需要更新。

也添加这一行:

scrollView.frame = CGRectMake([Helper getScreenWidth], contentViewHeight);


推荐阅读