簡體   English   中英

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

因此,我知道動畫塊中的圖層將被忽略,但我認為這也意味着要進行更新,因為在動畫過程中和動畫之后它仍然保持正方形。 是否有解決方案,不需要我也只為圖層創建Core Animation?

因此,您對此感興趣的塊似乎是Completion塊。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM