我在 UIView 中有一个元素,它有一个约束,规定它应该始终距离视图底部 10 像素。然后,我尝试为该视图的高度设置动画,使其看起来从屏幕上滑下。根据约束,元素应始终距视图底部 10 像素。当我像这样添加视图时,这是正确的......
printView *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"printView"];
[self addChildViewController:vc];
vc.view.frame = CGRectMake(0, 60, vc.view.frame.size.width, HEIGHT);
vc.view.layer.masksToBounds = FALSE;
[vc.view.layer setShadowOffset:CGSizeMake(0.0, 5.0)];
[vc.view.layer setShadowOpacity:0.8];
vc.view.layer.shadowColor = [[UIColor blackColor] CGColor];
vc.view.layer.shadowRadius = 8;
vc.view.clipsToBounds = TRUE;
[self.view insertSubview:vc.view aboveSubview:docWebView];
我可以将 HEIGHT 更改为我想要的任何值,并且元素始终距视图底部 10 像素。当我尝试设置高度动画时,问题就出现了
printView *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"printView"];
[self addChildViewController:vc];
vc.view.frame = CGRectMake(0, 60, vc.view.frame.size.width, 0);
vc.view.layer.masksToBounds = FALSE;
[vc.view.layer setShadowOffset:CGSizeMake(0.0, 5.0)];
[vc.view.layer setShadowOpacity:0.8];
vc.view.layer.shadowColor = [[UIColor blackColor] CGColor];
vc.view.layer.shadowRadius = 8;
vc.view.clipsToBounds = TRUE;
[self.view insertSubview:vc.view aboveSubview:docWebView];
[UIView animateWithDuration:5.0 animations:^{
vc.view.frame = CGRectMake(0, 60, vc.view.frame.size.width, 200);
[self.view setNeedsDisplay];
}];
该约束不再受约束,并且视图不再与元素始终距离底部 10 像素的位置滑入,而是看起来元素未被覆盖,因为元素不随视图移动。我希望我能很好地解释这一点。换句话说,我想要地图被拉下来的效果,但相反,它看起来像是地图已经在那里,并且覆盖它的一张纸被拉走了。感谢您的帮助。