【问题标题】:Subviews not appearing when UIScrollView is enabled启用 UIScrollView 时不显示子视图
【发布时间】:2015-08-04 05:47:41
【问题描述】:

在我的应用程序中,有一个子视图用于实现自动完成。它在单击按钮时出现。它在正常情况下工作正常。但是当我将全部内容嵌入到 UIScrollView 中时,它就不起作用了。这是我的代码

_scrollArea=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1000)];
_scrollArea.contentSize=CGSizeMake(320, 1000);
_scrollArea.scrollEnabled=YES;
_scrollArea.userInteractionEnabled=YES;
[self.view addSubview:_scrollArea];
_viewForAuto.hidden=false;

现在这里是按钮点击的动作调用

- (IBAction)buttonOnFromPlace:(id)sender {
_selectedSlot=1;
_viewForAuto.hidden=false;
[self.view bringSubviewToFront:_viewForAuto];

[_autoFillData removeAllObjects];
[_theTable reloadData];}

更新:滚动本身不起作用

更新 2:更新代码(将子视图放在前面,无法滚动)

_scrollArea.contentSize=CGSizeMake(320, 700);
_scrollArea.scrollEnabled=YES;

动作调用

- (IBAction)buttonOnFromPlace:(id)sender {
_selectedSlot=1;
_viewForAuto.hidden=false;
[_scrollArea bringSubviewToFront:_viewForAuto];

[_autoFillData removeAllObjects];
[_theTable reloadData];}

【问题讨论】:

  • _viewForAuto 的父视图是什么。
  • scrollArea 是它的超级视图
  • 试试这个 [_scrollArea bringSubviewToFront:_viewForAuto];而不是 [self.view bringSubviewToFront:_viewForAuto];
  • 对不起,控件没有流入按钮的动作
  • 现在我通过删除 [self.view addSubview:_scrollArea] 来控制流向动作部分;但你建议的修改不起作用

标签: ios uiview uiscrollview


【解决方案1】:

如果我们想要 UIScrolllView 滚动,我们的 contentSize 必须大于框架大小。如果你想要滚动视图,试试这个

_scrollArea.contentSize = CGSizeMake(_scrollArea.frame.size.width,2*_scrollArea.frame.size.height);

【讨论】:

    猜你喜欢
    • 2011-09-18
    • 2012-07-05
    • 1970-01-01
    • 2020-08-21
    • 1970-01-01
    • 1970-01-01
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多