zoukankan      html  css  js  c++  java
  • Tips:取消UICollectionView的隐式动画

    http://www.cocoachina.com/ios/20151204/14211.html

    UICollectionView在reloadItems的时候,默认会附加一个隐式的fade动画,有时候很讨厌,尤其是当你的cell是复合cell的情况下(比如cell使用到了UIStackView)。

    下面几种方法都可以帮你去除这些动画

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    //方法一
    [UIView performWithoutAnimation:^{
        [collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
    }];
    //方法二
    [UIView animateWithDuration:0 animations:^{
        [collectionView performBatchUpdates:^{
            [collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
        } completion:nil];
    }];
         
    //方法三
    [UIView setAnimationsEnabled:NO];
    [self.trackPanel performBatchUpdates:^{
        [collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
    } completion:^(BOOL finished) {
        [UIView setAnimationsEnabled:YES];
    }];

    如果你的APP只支持iOS7+ 推荐使用第一种方式performWithoutAnimation(感谢@sunnyxx的tip) 简单方便

    but

    问题还没有结束 上面介绍的方法只能解决UIView的Animation 如果你的cell中还包含有CALayer的动画 比如这样

    1
    2
    3
    4
    5
    6
    - (void)layoutSubviews
    {
        [super layoutSubviews];
         
        self.frameLayer.frame = self.frameView.bounds;
    }

    上述情况多用于自定义控件使用了layer.mask的情况 如果有这种情况 上面提到的方法是无法取消CALayer的动画的 但是解决办法也很简单

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    - (void)layoutSubviews
    {
        [super layoutSubviews];
         
        [CATransaction begin];
        [CATransaction setDisableActions:YES];
         
        self.frameLayer.frame = self.frameView.bounds;
         
        [CATransaction commit];
         
    }

    done!

  • 相关阅读:
    多态
    163VIP邮箱哪个好?为什么要使用邮箱客户端?
    163邮箱的格式什么样的?常见的电子邮箱品牌有哪些?
    申请企业邮箱需要准备什么材料?外贸邮箱怎么注册?
    《10秒挑战》h5游戏案例分析
    H5反应类爆款游戏分享
    企业邮箱多少钱,哪家企业邮箱更具性价比?
    注册申请企业邮箱,哪家最优惠 #万元礼包来袭#
    购买一个163VIP邮箱,3位超短靓号更惊喜~
    小程序对H5游戏的技术分析
  • 原文地址:https://www.cnblogs.com/itlover2013/p/5024446.html
Copyright © 2011-2022 走看看