iOS版:如何做一件有生命的新的自动布局约束(高度) [英] iOS: How does one animate to new autolayout constraint (height)

查看:286
本文介绍了iOS版:如何做一件有生命的新的自动布局约束(高度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来没有使用过的自动布局约束之前,。我有一个小的新的应用我的工作,并注意到NIB的意见都默认为自动版式。所以,我想我会趁机工作的的并尝试找出其中苹果与此打算。

I've never worked with autolayout constraints before. I have a small new app I'm working on and noticed that the NIB's views are defaulting to autolayout. So, I figured I'd take the opportunity to work with it and try to figure out where Apple is going with this.

第一个挑战:

我需要一个调整和的MKMapView我想它动画到新的位置。如果我来做,我已经习惯了:

I need to resize an MKMapView and I'd like to animate it to the new position. If I do this the way I'm used to:

[UIView animateWithDuration:1.2f
     animations:^{
         CGRect theFrame = worldView.frame;
         CGRect newFrame = CGRectMake(theFrame.origin.x, theFrame.origin.y, theFrame.size.width, theFrame.size.height - 170);
         worldView.frame = newFrame;
}];

...那么会的MKMapView捕捉恢复到原来的高度,每当一个同级观点得到更新(在我的情况下,UISegmentedControl的标题被更新 [myUISegmentedControl的setTitle:newTitle的forSegmentAtIndex:0] )。

所以,我的认为的我想要做的是从等于父视图的HIGHT改变的MKMapView的约束是相对UISegmentedControl的顶部,它的的内容包括:五:[的MKMapView] - (16) - [UISegmentedControl]

So, what I think I want to do is change the constraints of the MKMapView from being equal to the parent view's hight to being relative to the top of the UISegmentedControl that it was covering: V:[MKMapView]-(16)-[UISegmentedControl]

我要的是对的MKMapView高度缩短,使地图视图下的某些控件显露。要做到这一点我的认为的我需要约束从固定的全尺寸视图更改为船底被限制在一个UISegmentedControl顶......我想它作为动画视图缩小到新的大小。

What I want is for the MKMapView height to shorten so that some controls beneath the map view are revealed. To do so I think I need to change the constraint from a fixed full size view to one where the bottom is constrained to the top of a UISegmentedControl...and I'd like it to animate as view shrinks to new size.

如何去这件事吗?

编辑 - 这个动画的的动画虽然视图的底部也向上移动170瞬间:

Edit - this animation is not animating though the bottom of the view does move up 170 instantly:

    [UIView animateWithDuration:1.2f
         animations:^{
             self.nibMapViewConstraint.constant = -170;

    }];

nibMapViewConstraint 是有线起来IB底部垂直空间的限制。

and the nibMapViewConstraint is wired up in IB to the bottom Vertical Space constraint.

推荐答案

更新后的约束:

[UIView animateWithDuration:0.5 animations:^{[self.view layoutIfNeeded];}];

替换 self.view 同为包含视图的引用。

这篇关于iOS版:如何做一件有生命的新的自动布局约束(高度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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