【问题标题】:IOS8 Uiscrollview Inside uiview IssueIOS8 uiscrollview里面的uiview问题
【发布时间】:2014-09-18 12:50:22
【问题描述】:

在IOS8我不能在UIScrollView下面添加UIView。我使用的代码如下

UIScrollView *MainScroll=[[UIScrollView alloc]init];
MainScroll.backgroundColor=[UIColor redColor];
MainScroll.frame=CGRectMake(0, 0, 365,470);
[self.view addSubview:MainScroll];

UIView *HeaderView=[[UIView alloc]init];
HeaderView.backgroundColor=[UIColor orangeColor];
HeaderView.frame=CGRectMake(0,0,width,20);
[MainScroll addSubview:HeaderView];

在此代码中,HeaderView 未放置在 MainScroll 的起点。它位于 UIScrollView 的一些空格之后。此问题仅在 IOS8 中发生。但在 IOS7 中它工作正常,符合我的预期。

【问题讨论】:

  • 您使用的是 iOS 8 Beta 版吗?因为您的代码在 iOS7 和 iOS8 中运行良好。
  • 这是测试版

标签: ios iphone ios7 ios8


【解决方案1】:

看到你的代码对我来说运行良好,我正在使用 Xcode 6 GM (iOS8 GM)。

代码:

UIScrollView *MainScroll=[[UIScrollView alloc]init];
MainScroll.backgroundColor=[UIColor redColor];
MainScroll.frame=CGRectMake(10, 100, 300, 200);
[self.view addSubview:MainScroll];

UIView *HeaderView=[[UIView alloc]init];
HeaderView.backgroundColor=[UIColor orangeColor];
HeaderView.frame=CGRectMake(0, 0, 300, 20);
[MainScroll addSubview:HeaderView]; 

iOS 8 结果:

iOS 7 结果:

【讨论】:

  • 我也只使用 GM。我从 uiscrollview 得到 20px 以下
  • 你能在嵌入导航控制器后尝试相同的代码
  • 如果我嵌入导航控制器,它将放置在滚动视图下方的一些空格之后..如果我删除导航控制器,它将放置在滚动视图下方
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-19
  • 2011-07-03
  • 2011-03-11
  • 1970-01-01
  • 2013-04-24
  • 2013-03-04
相关资源
最近更新 更多