ios - 如何在旋转时调整 CollectionView 的特定单元格的大小?

标签 ios uicollectionview uicollectionviewcell

最终结果是在设备旋转后调整 cell.title 和 cell.description 的大小,使其填满整个屏幕。这个 Collection View Controller 位于 View Controller 内,因此我需要一个特定于单元格的解决方案。

- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{


  if(collectionView == collection1)
  {


SliderCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"articleCellslider1"
                                                                           forIndexPath:indexPath];

NSDictionary *item = [_articleListslider objectAtIndex:indexPath.item];

// set the article image
[cell.image setImageWithURL:[item objectForKey:@"image"]];

// set the text of title UILabel
cell.title.text = [NSString stringWithFormat:@"%@\n\n\n\n", [item objectForKey:@"title"]];
cell.title.textColor = [UIColor colorWithRed:33.0f/255.0f green:74.0f/255.0f blue:146.0f/255.0f alpha:1.0f];
cell.title.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:0.5f];

// set the text of summary UILabel
cell.description.text = [NSString stringWithFormat:@"%@\n\n\n\n\n\n\n\n\n", [item objectForKey:@"description"]];
cell.description.font = [UIFont fontWithName:@"Helvetica Neue" size:14];
cell.description.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green:255.0f/255.0f blue:255.0f/255.0f alpha:0.5f];

cell.targetURL = [item objectForKey:@"link"];

cell.sliderphoto = [item objectForKey:@"sliderphoto"];

cell.date.text = [NSString stringWithFormat:@"%@\n\n\n\n", [item objectForKey:@"pubDate"]];

cell.category.text = [NSString stringWithFormat:@"%@\n\n\n\n", [item objectForKey:@"category"]];


return cell;

[self performSegueWithIdentifier:@"Slider" sender:indexPath];



}

我想要在旋转时专门调整大小的单元格是 cell.title 和 cell.description

最佳答案

重写 UIviewController 的旋转委托(delegate)方法之一,尝试 willRotateToInterfaceOrientation (可能是 did 而不是 will 更好)然后当你捕获它时,重新加载你的 TableView 并设置一些标志来知道它已旋转。

然后实现UICollectionViewDelegateFlowLayout、collectionView:layout:sizeForItemAtIndexPath: (根据方向更改此处的大小)

关于ios - 如何在旋转时调整 CollectionView 的特定单元格的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18992603/

相关文章:

iphone - AVFoundation:捕获视频在约 30 分钟后失败

ios - FileManager 找不到音频文件

swift - tvOS:CollectionView 在模拟器上边界完美,但在设备屏幕外

ios - 有没有一种更有效的方法可以在不手动指定每个 View 的情况下向 UICollectionViewCell 添加相同的 View ?

iOS - 处理指向已释放变量的异步任务

iphone - 如何从 Objective-C 中的 View Controller 调用我的数据库类?

ios - 如何使用自定义单元格大小提高 UICollectionView 的性能?

ios - Swift:根据单元格数量动态更改单元格高度

ios - 旋转时的 UICollectionViewCell alpha 值

ios - 从 UICollectionViewCell 使用 UICollectionView