在 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 中,它工作正常,符合我的预期。
最佳答案
看到这个你的代码对我来说工作正常&我正在使用 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 结果:
关于IOS8 UIscrollview 内部 uiview 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25913088/