我在 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 像素,看起来元素正在被覆盖,因为元素不随视图移动。我希望我能很好地解释这一点。换句话说,我想要一张地图被拉下的效果,但看起来地图已经在那里,而覆盖它的一张纸被拉走了。谢谢你的帮助。