小编Kel*_*ong的帖子

UICollectionView performBatchUpdates在旋转设备时导致collectionview错位

如果我旋转设备当collectionview performBatchUpdate与reloadItemsAtIndexPaths时,集合视图将被放错位置.但观点仍将保持不变.

要简单地解决此问题:

setting [UIView setAnimationEnabled: NO]; in willRotateToInterfaceOrientation
+ 
setting [UIView setAnimationEnabled: YES]; in didRotateToInterfaceOrientation
Run Code Online (Sandbox Code Playgroud)

但我不认为这是解决这个问题的好方法.

有没有人有更好的主意?

干杯.

这是我的代码:

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    NSLog(@"Before Rotation");
    NSLog(@"collecitonview Rect : %@", NSStringFromCGRect(self.collectionView.frame));
    NSLog(@"view Rect : %@", NSStringFromCGRect(self.view.frame));
}

    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
    NSLog(@"After Rotation");
    NSLog(@"collecitonview Rect : %@", NSStringFromCGRect(self.collectionView.frame));
    NSLog(@"view Rect : %@", NSStringFromCGRect(self.view.frame));
}

    - (void) viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    for(int i = 0 ; i < 30; i++){
        NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
            CGFloat hue = arc4random() % …
Run Code Online (Sandbox Code Playgroud)

ios uicollectionview

6
推荐指数
1
解决办法
1094
查看次数

标签 统计

ios ×1

uicollectionview ×1