【发布时间】:2015-05-20 08:53:14
【问题描述】:
我有一个包含一个子视图的容器视图。我想用另一个大小与原始大小不同的视图替换这个子视图,因此容器也应该调整大小。这就是我想要做的事情
UIView *content = NEW_CONTENT;
content.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentContainer layoutIfNeeded]; // the container view
// make the old content disappear first
[UIView animateWithDuration:0.3
animations:^{
UIView *oldContent = [self.contentContainer.subviews firstObject];
oldContent.alpha = 0.0f;
}
completion:^(BOOL finished) {
// then replace it with a new content
[UIView transitionWithView:self.contentContainer
duration:0.1
options:0
animations:^{
[[self.contentContainer.subviews firstObject] removeFromSuperview];
[self.contentContainer addSubview:content];
[content autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsZero];
[self.contentContainer layoutIfNeeded];
}
completion:^(BOOL finished) { // completion stuff}];
}];
旧的内容不透明度动画正确,但布局更改时没有任何动画。我该如何解决?
【问题讨论】:
标签: ios objective-c autolayout uikit