Ios 向上移动视图时如何使用现有约束autolayout?
我正在使用下面的代码使用UIViewAnimation从底部显示和隐藏子视图---->top或top---->bottomIos 向上移动视图时如何使用现有约束autolayout?,ios,iphone,animation,autolayout,Ios,Iphone,Animation,Autolayout,我正在使用下面的代码使用UIViewAnimation从底部显示和隐藏子视图---->top或top---->bottom -(IBAction)showClander { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationBeginsFromCurrentState:NO]; [UIView setAnimationDuration:0.50]; pickerView.frame = C
-(IBAction)showClander
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationDuration:0.50];
pickerView.frame = CGRectMake(0, 568-368, pickerView.frame.size.width, pickerView.frame.size.height);
[UIView commitAnimations];
}
-(void)hideClander
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:NO];
[UIView setAnimationDuration:0.50];
pickerView.frame = CGRectMake(0, pickerView.frame.origin.y+368, pickerView.frame.size.width, pickerView.frame.size.height);
[UIView commitAnimations];
}
当我没有使用Autolayout时,上面的代码运行良好,但因为我的应用程序同时支持纵向和横向,所以我应该使用Autolayout
现在的问题是如何为这个移动视图设置不同的约束,对于静态视图,我设置了不同的约束,正如下面的屏幕截图所示
如上截图所示,当我试图将其更改为568(这是我的要求)时,显示(Y值为371),然后我没有得到上述截图的结果
所以问题是,有没有任何方法可以在不做太多更改的情况下使用现有约束来移动对象,从而实现上述结果?如果您有任何建议,我们将不胜感激。请提前感谢您可以为约束本身的更改设置动画。更改需要更改的约束的
常量
值,并在动画块内调用layoutifneed
我自己代码中的示例:
NSLayoutConstraint* con = self.v_verticalPositionConstraint;
con.constant -= 100;
[UIView animateWithDuration:1 animations:^{
[self.v layoutIfNeeded];
} completion:nil];
但是,通常情况下,动画和自动布局是敌人,因为它们试图以两种不同的方式更改视图的帧。请参阅我书中的讨论:谢谢,这很有意义,但我很困惑是否应该删除superview约束的底部空间?当前它有0个常量值。