Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/117.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 设置自动布局“leftAnchor”约束更改的动画_Ios_Objective C_Autolayout_Nslayoutconstraint - Fatal编程技术网

Ios 设置自动布局“leftAnchor”约束更改的动画

Ios 设置自动布局“leftAnchor”约束更改的动画,ios,objective-c,autolayout,nslayoutconstraint,Ios,Objective C,Autolayout,Nslayoutconstraint,我有一个UIView,我正在初始化它,以便在视图的右侧启动“屏幕外”视图,占100%。我通过以下方式来实现这一点: [childView.leftAnchor constraintEqualToAnchor: superview.rightAnchor constant: 1.0].active = YES; [UIView animateWithDuration: 5 animatio

我有一个UIView,我正在初始化它,以便在视图的右侧启动“屏幕外”视图,占100%。我通过以下方式来实现这一点:

[childView.leftAnchor constraintEqualToAnchor: superview.rightAnchor
                                     constant: 1.0].active = YES;
[UIView animateWithDuration: 5
                 animations: ^{
                     [childView.leftAnchor constraintEqualToAnchor: superview.leftAnchor
                                                               constant: 1.0].active = YES;
                 }];
然后,我想从左侧“滑动”视图。我想也许可以做以下几点:

[childView.leftAnchor constraintEqualToAnchor: superview.rightAnchor
                                     constant: 1.0].active = YES;
[UIView animateWithDuration: 5
                 animations: ^{
                     [childView.leftAnchor constraintEqualToAnchor: superview.leftAnchor
                                                               constant: 1.0].active = YES;
                 }];
可能会这样做,但它会立即发生(没有动画,它只是“出现”)

是否可以使用自动布局锚来提供动画

[childView.leftAnchor constraintEqualToAnchor: superview.leftAnchor constant: 1.0].active = YES;
[UIView animateWithDuration: 5
                 animations: ^{
                     [childView layoutIfNeeded];
                 }];
这应该可以做到。约束更改本身不应该在动画块中,而应该在布局调用中。您可能还应该禁用/删除您所做的初始约束,因为这个新约束与它直接冲突(您可能会在控制台中看到警告)