简体   繁体   中英

iOS update CALayer in UIView animation block

So i have the following function

- (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];
         }];
    }
}

and within _profileInfoVC i have it doing

-(void)viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];

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

So i am aware that layers are ignored within the animation blocks but I assume this also means updating at all since it remains quite square during and after the animation. Is there a solution to this that does not require me also creating a Core Animation for just the layer?

So it seems the block you are interested in this regard is the Completion 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];
         }
         completion:^(BOOL finished)
         {
             [_profileInfoVC viewWillLayoutSubviews];
         }];
    }
}

the above seems to have fixed my issue, also i was never really a fan of directly calling viewWillLayoutSubviews directly so that line has been changed to [_profileInfoVC.view setNeedsLayout];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM