更改自动版式启用控制的恢复变更的位置? [英] Changing the position of the autolayout enabled control revert the changes?

查看:174
本文介绍了更改自动版式启用控制的恢复变更的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的一部分被显示UIcollectionView列表,如果用户向下滑动屏幕,我会从的viewController的顶部present的的UISearchBar动画。
我做了所有的人都在一个单独的viewController。

A part of my application is showing a list in UIcollectionView, if the user swipe down the screen I will present the UISearchBar with animation from the top of the viewController. I did all of them in a separate viewController.

我使用的自动布局在的viewController定位控制。

I use autolayout to position the controls in that viewController.

我移动搜索栏形式为y = -88到y = 0和移动的CollectionView向下腾出空间搜索栏动画当用户向下滑动屏幕,我的问题是,如果我做调用reloadData到的CollectionView,这两个搜索栏和移动的CollectionView他们的previous autolayouted位置

I move the search bar form y=-88 to y=0 and move the collectionView down to make space for searchBar with animation when the user swipe down the screen, my problem is that if I make call to reloadData to collectionView, both search bar and CollectionView move to their previous autolayouted positions

我用下面的动画将它们移动

I use below animation to move them

[UIView animateWithDuration:0.4 animations:^(void){
        fileSearchBar.frame=fileSearchBar.frame=CGRectOffset(fileSearchBar.frame, 0,88);
        chartsCollectionView.frame=gridFrame;///gridFrame is calculated to move down
    }]; 

我有没有办法阻止他们移动到他们的pre-计算出的位置

I there a way to stop them moving to their pre-calculated position

推荐答案

当您使用自动布局,必须不设置帧。你必须改变的约束,让间接改变帧。

When you use auto layout, you must not set frames. You have to change constraints and let that change the frames indirectly.

苹果的自动布局指南显示<一个href=\"https://developer.apple.com/Library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/AutoLayoutbyExample/AutoLayoutbyExample.html#//apple_ref/doc/uid/TP40010853-CH5-SW15\"相对=nofollow> 生动活泼的例子:

Apple's Auto Layout Guide shows an example of animating:

[containerView layoutIfNeeded]; // Ensures that all pending layout operations have been completed
[UIView animateWithDuration:0.4 animations:^{
     // Make all constraint changes here
     [containerView layoutIfNeeded]; // Forces the layout of the subtree animation block and then captures all of the frame changes
}];

您不会告诉你如何设置的限制,所以我不能告诉你如何修改它们移动搜索栏和集合视图。理想情况下,你只需要设置的限制之一的属性。 (您的约束应该设置这样动人的一件事使对方自动调整自身。)

You don't show how you set up your constraints, so I can't show you how to modify them to move the search bar and collection view. Ideally, you'd just need to set the constant property of one of the constraints. (Your constraints should be set up so that moving one thing causes the other to adjust itself automatically.)

这篇关于更改自动版式启用控制的恢复变更的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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