iOS 更新 UIView 动画块中的 CALayer

iOS update CALayer in UIView animation block

所以我有以下功能

- (void)setMoreMenuHidden:(BOOL)hidden animated:(BOOL)animated completion:(void(^)(BOOL))completion
{
    if (!hidden)
    {
        [self.view layoutIfNeeded];
        [self.view setNeedsUpdateConstraints];
        [UIView animateWithDuration:0.5f animations:^
         {
             [self.view layoutIfNeeded];
             [_profileInfoVC viewWillLayoutSubviews];
         }];
    }
}

_profileInfoVC 之内我已经做到了

-(void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

    [self.view layoutIfNeeded];
    self.pictureImageView.layer.cornerRadius = self.pictureImageView.frame.size.width/2;
    self.pictureImageView.clipsToBounds = YES;
}

所以我知道动画块中的层被忽略了,但我认为这也意味着更新,因为它在动画期间和之后仍然非常方形。有没有不需要我也为图层创建核心动画的解决方案?

看来您对这方面感兴趣的区块是完成区块。

- (void)setMoreMenuHidden:(BOOL)hidden animated:(BOOL)animated completion:(void(^)(BOOL))completion
{
    if (!hidden)
    {
        [self.view layoutIfNeeded];
        [self.view setNeedsUpdateConstraints];
        [UIView animateWithDuration:0.5f animations:^
         {
             [self.view layoutIfNeeded];
         }
         completion:^(BOOL finished)
         {
             [_profileInfoVC viewWillLayoutSubviews];
         }];
    }
}

以上似乎已经解决了我的问题,而且我从来都不喜欢直接直接调用 viewWillLayoutSubviews,因此该行已更改为 [_profileInfoVC.view setNeedsLayout];