2015-07-28 65 views
1

所以,我有以下功能的iOS更新的CALayer

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

所以我知道層動畫塊中忽略,但我認爲這也意味着更新,因爲在動畫期間和之後它仍然是相當正方形的。有沒有解決方案,這不需要我也爲圖層創建一個核心動畫?

回答

0

所以看來你對這方面感興趣的塊是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];

風扇