Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/105.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
Ios 如何在设备方向更改时重新排列集合视图单元格_Ios_Objective C_Uicollectionview_Uicollectionviewlayout - Fatal编程技术网

Ios 如何在设备方向更改时重新排列集合视图单元格

Ios 如何在设备方向更改时重新排列集合视图单元格,ios,objective-c,uicollectionview,uicollectionviewlayout,Ios,Objective C,Uicollectionview,Uicollectionviewlayout,在纵向模式下,集合视图看起来很好。但当它处于横向模式时,细胞不会重新排列。。他们呆在同一个地方 我添加了autolayout,这样集合视图可以拉伸以填充屏幕,并且集合视图具有恒定的高度约束 我的视图层次结构是这样的 视图->滚动视图->内容视图|-->有问题的集合视图(通知标签上方的一个) | |->Tableview(通知标签后的一个) | |->集合视图(顶部的黑色空间) 集合视图的代码是 -(NSInteger)numberOfSectionsInCollectionView:(UICol

在纵向模式下,集合视图看起来很好。但当它处于横向模式时,细胞不会重新排列。。他们呆在同一个地方

我添加了autolayout,这样集合视图可以拉伸以填充屏幕,并且集合视图具有恒定的高度约束

我的视图层次结构是这样的

视图->滚动视图->内容视图|-->有问题的集合视图(通知标签上方的一个) | |->Tableview(通知标签后的一个) | |->集合视图(顶部的黑色空间)

集合视图的代码是

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;}
-(NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
 return 14;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
             cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (collectionView==self.offerCollectionView) {
    sliderCollectionInHomeScreen *myCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"reuseIdForSlider"
                                                                                     forIndexPath:indexPath];
    myCell.labelForShopName.text = [[self.arrayForOfferSlider objectAtIndex:indexPath.row] objectForKey:@"shop_name"];
    myCell.labelForOfferName.text = [[self.arrayForOfferSlider objectAtIndex:indexPath.row] objectForKey:@"offer_title"];
    myCell.offerImage.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[[self.arrayForOfferSlider objectAtIndex:indexPath.row] objectForKey:@"img_url"]]]];

    ;


    return myCell;
}

我不知道这是否正确。但这对我来说暂时有效

-(void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrient{

//[self.categoryCollectionView reloadData];
UICollectionViewFlowLayout * lay =[[UICollectionViewFlowLayout alloc] init];
if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
    [lay setScrollDirection:UICollectionViewScrollDirectionVertical];
}
else{

    [lay setScrollDirection:UICollectionViewScrollDirectionHorizontal];
}


[self.CollectionView setCollectionViewLayout:lay];


}

共享一些代码,它是否给出任何错误或警告?它不显示任何错误。共享一些集合视图的代码。