[英]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 在
_profileInfoVC
我正在执行此操作
-(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?
是否有解决方案,不需要我也只为图层创建Core Animation?
So it seems the block you are interested in this regard is the Completion block. 因此,您对此感兴趣的块似乎是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];
}];
}
}
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];
上面的代码似乎已经解决了我的问题,我也不是真正地直接调用
viewWillLayoutSubviews
来将行更改为[_profileInfoVC.view setNeedsLayout];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.