【问题标题】:iOS update CALayer in UIView animation blockiOS 更新 UIView 动画块中的 CALayer
【发布时间】:2015-07-28 07:17:12
【问题描述】:

所以我有以下功能

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

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

【问题讨论】:

    标签: ios autolayout calayer uiviewanimation


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-15
      • 1970-01-01
      • 2015-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-03
      相关资源
      最近更新 更多