UICollectionView - resizing cells on device rotate - Swift

后端 未结 9 1568
醉梦人生
醉梦人生 2020-12-04 23:12

I\'ve created a UICollectionView, so that I can arrange views into neat columns. I\'d like there to be a single column on devices > 500 pixels wide.

In order to achi

9条回答
  •  醉梦人生
    2020-12-05 00:12

    This is for others with maybe same special case. Situation: I included a UICollectionView as a UITableViewCell in a table view controller. The row height was set to UITableViewAutomaticDimension to adapt on number of cells in the collection view. It didn't layout correctly on device rotation although other cells with dynamic content in the same table view behaved correctly. After a long research I found a solution that worked:

    - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator {
        [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
        [self reloadTableViewSilently];
    }
    
    - (void) reloadTableViewSilently {
        dispatch_async(dispatch_get_main_queue(), ^{
    // optional: [UIView setAnimationsEnabled:false];
            [self.tableView beginUpdates];
            [self.tableView endUpdates];
    // optional: [UIView setAnimationsEnabled:true];
        });
    }
    

提交回复
热议问题