Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IOS8 Uiscrollview内部uiview问题_Ios_Iphone_Ios7_Ios8 - Fatal编程技术网

IOS8 Uiscrollview内部uiview问题

IOS8 Uiscrollview内部uiview问题,ios,iphone,ios7,ios8,Ios,Iphone,Ios7,Ios8,在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]i

在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结果:

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 7结果:

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 Beta版本吗?Bcz您的代码在iOS 7和iOS 8中运行良好。这是s Beta版本,也是仅使用GM。Bt我从UIScrollView获得了20px以下的版本。您可以在嵌入导航控制器后尝试相同的代码吗?如果我嵌入导航控制器,它将放置在scrollview下面的一些空格之后。如果我删除导航控制器,它就是放置在滚动视图下方