如何用自动布局约束动画转移景色的iOS上 [英] How To shift a view with animation with auto layout constraints are on iOS

查看:211
本文介绍了如何用自动布局约束动画转移景色的iOS上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做中,我需要的观点了35个像素,以显示视图是该视图低于present转移的任务。

I am doing a task in which, i need to shift the view by 35 pixels in order to show a view which is present below that view.


你可以说我需要像插在上面的通知一间酒吧和35个像素在运行时移动现有的视图。

Or you can say i need to insert a bar like notification on top and shift the existing view by 35 pixels at runtime.

问题是与汽车的布局上,以支持所有屏幕。换档这里没有发生,因为我们希望....有什么建议?
顶视图有一个约束,它与顶视图距离是零,这需要在运行时改变,当我们以显示下面图。

The problem is with auto layout on in order to support all the screens. Shifting is not happening as we want.... Any suggestions here ? Top view has a constraint that its distance with top view is zero, which needs to change at runtime, when we to show the below view.

下面是移位前的屏幕:

Here are the screens before shifting :

移,并显示图像后:

在这里输入的形象描述

我给侧边栏视图中。
NotifView:黄认为,我们需要在运行时显示
twoView:我们需要转移到顶部显示notifview

I have given sidebar view as well. NotifView : yellow view that we need to show at runtime twoView : that we need to shift to display notifview on top.

- (无效)shiftTwoView:(* NSString的)摘要{

-(void)shiftTwoView:(NSString*)summary{

CGFloat shiftHeight = 35.0f;

CGRect twoRect = twoView.frame;
    twoRect.origin.y += shiftHeight;
    twoRect.size.height -= shiftHeight;


[UIView animateWithDuration:3.5
                 animations:^{
                     twoView.frame = twoRect;
                 }];

}

推荐答案

当您使用自动布局,则不需要设置这样的框架。你可以操纵的限制值编程方式做到这一点。由于您没有讲明你在这里应用的所有限制,我将解释什么,你要求所有这样做。

When you are using Auto Layout, you need not set frames like that. You can manipulate the constraints values programmatically to do it. As you haven't made it clear what all constraints you have applied here, i will explain what all you require to do so.

notifyview: - leading = 0, trailing = 0, top = 0, height = 0;  
twoView: - leading = 0, trailing = 0, top(to notifview) = 0; bottom = 0;

现在创建一个IBOutlet为 notifyview 的高度约束,可以说 notifyViewHeightConstraint

Now create an IBOutlet for the height constraint of notifyview, lets say notifyViewHeightConstraint.

现在,以显示你的notifyView的内容,所有你需要做的是增加它的高度。默认情况下此高度 0 从故事板。你可以像 notifyViewHeightConstraint.constant = 40改变它; 。一旦你完成,你需要再次消失,你可以设置值回0;

Now to display the content of your notifyView, all you need to do is increase the height of it. By default this height is 0 from storyboard. You can change it like notifyViewHeightConstraint.constant = 40;. Once you are done and you need to disappear it again, you can set the constant value back to 0;

-(void)shiftTwoView:(NSString*)summary  
{  
     notifyViewHeightConstraint.constant = 40;   
    [UIView animateWithDuration:2.0 animations:^{  
            [self.view layoutIfNeeded];  
    }]; 
}

这篇关于如何用自动布局约束动画转移景色的iOS上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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