ios – UIViewAnimationOptionLayoutSubviews的工作原理示例?

前端之家收集整理的这篇文章主要介绍了ios – UIViewAnimationOptionLayoutSubviews的工作原理示例?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Apple的文档将UIViewAnimationOptionLayoutSubviews描述为:

Lay out subviews at commit time so that they are animated along with
their parent.

这是我感兴趣的代码示例.我希望为detailView的-layoutSubviews设置动画;但是,它似乎没有布局detailView的子视图,所以我不确定它实际上有什么影响.

void (^animation) () = ^
    {
        [self.detailView setNeedsLayout];
        [self.detailView layoutIfNeeded];
    };

    [UIView animateWithDuration:0.5
                          delay:0.0
                        options:UIViewAnimationOptionLayoutSubviews
                     animations:^{
                         animation();
                     }
                     completion:nil];

解决方法

由于您希望第二个动画从第一个动画的当前状态(无论是否完成)发生,我建议在设置第二个动画时使用UIViewAnimationOptionLayoutSubviews选项.
[UIView animateWithDuration:0.2
                      delay:0.0
                    options:UIViewAnimationOptionLayoutSubviews
                 animations:^{
                     CGAffineTransform settingsTransform = CGAffineTransformMakeTranslation(self.animatedView.frame.size.width,0);
                        self.animatedView.transform = settingsTransform;
                 } 
completion:nil];
原文链接:https://www.f2er.com/iOS/333415.html

猜你在找的iOS相关文章