AutoLayout 动画

AutoLayout 动画

how to animate constraint changes?


  • Need call layoutIfNeeded within the animation block.
  • Need to call it specifically on the parent view, not the child view that has the constraints attached to it.

e.g:

- (void)moveBannerOffScreen {
    [self.view layoutIfNeeded];     // parent view call layoutIfNeeded 

    _addBannerDistanceFromBottomConstraint.constant = -32;
    [UIView animateWithDuration:5
        animations:^{
            [self.view layoutIfNeeded]; // Called within the block 
        }];
}

- (void)moveBannerOnScreen { 
    [self.view layoutIfNeeded];

    _addBannerDistanceFromBottomConstraint.constant = 0;
    [UIView animateWithDuration:5
        animations:^{
            [self.view layoutIfNeeded]; // Called on parent view
        }];
    bannerIsVisible = TRUE;
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,456评论 0 23
  • 多年前,我还在一个二线城市的三流大学就读,期间去北京旅游一次,再次点燃我到首都工作生活的梦想。 现在想来,小学时爸...
    叶深沉阅读 1,755评论 1 1
  • 从阿猫阿狗到三姑六婆 从隔壁的村到儿时的路 从天上的月亮到河里的流水 从夏天的风到冬天的火 从你走过的路到你见过的...
    更向远行阅读 1,306评论 0 2
  • 所谓潜在客户,是指对某类产品或服务存在需求且具备购买能力的待开发客户。 每一个客户身边都要200个亲...
    l小梨子阅读 3,408评论 0 1
  • (1)因为要用MD5来加密文件的名称,所以就去查了下MD5的资料,然后发现例子是这样子的: 然后还有这样子的: 反...
    eveo阅读 1,872评论 0 0