动画与约束的UIView框架 [英] Animating UIView frame with constraints

查看:106
本文介绍了动画与约束的UIView框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在与说它应该始终从视图的底部10像素的约束一个UIView的元素。我试图然后使其显示滑下屏幕动画这一观点的高度。据约束,该元素应始终从视图的底部10个像素。当我添加视图像这样这也是如此...

I have an element in a UIView with a constraint that says it should always be 10 pixels from the bottom of the view. I am then attempting to animate this view's height so that it appears to slide down the screen. According to the constraint, the element should always be 10 pixels from the bottom of the view. This holds true when I add the view like so...

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];

我可以改变高度,以任何我想要和元素总是从视图的底部10个像素。问题是当我尝试动画的高度

I can change HEIGHT to whatever I want and the element is always 10 pixels from the bottom of the view. The problem comes when I try to animate the height

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个象素,它看起来像元件被揭露,因为该元件不与视图中移动。我希望我解释这不够好。把它的另一种方式,我要对地图的效果被推倒,而是它看起来像地图已经存在和一张纸,是覆盖它被拉走。感谢您的帮助。

The constraint is no longer honored and instead of the view sliding in with the element always 10 pixels from the bottom, it looks like the element is being uncovered because the element does not move with the view. I hope I am explaining this well enough. To put it another way, I'm going for the effect of a map being pulled down, but instead it looks like the map is already there and a piece of paper that is covering it is being pulled away. Thanks for your help.

推荐答案

在使用约束,你不应该设置框,你应该调整的约束。当您最初设置的限制,你应该一个IBOutlet的高度约束,然后在动画的动画块的恒定参数。如果你有叫heightCon的高度限制,你可以这样做:

When using constraints, you shouldn't be setting frames, you should be adjusting the constraints. When you initially set up your constraints, you should make an IBOutlet to the height constraint, and then animate its constant parameter in the animation block. If you had a height constraint called heightCon, you could do this:

[UIView animateWithDuration:5.0 animations:^{
        self.heightCon.constant = 200
        [self.view layoutIfNeeded];
    }];

我不知道你的结构,即self.view可能要代替vc.view。

I'm not sure about your structure, that self.view might have to be vc.view instead.

修改后:

这是动画的高度约束的方式,但我不知道这是你想要做的做到你以后是什么。我真的不知道,让您的最后一个段落的内容。如果你被拉下要一个地图的效果,好像需要进行任何动画或消除底部的约束。

This is the way to animate a height constraint, but I'm not sure that's what you want to do to accomplish the look you're after. I'm not really sure what to make of your last paragraph. If you're going for an effect of a map being pulled down, it seems like the bottom constraint needs to be either animated or eliminated.

这篇关于动画与约束的UIView框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆