Ios 当GMSMapView移动时,如何设置NSLayoutConstraint动画?

Ios 当GMSMapView移动时,如何设置NSLayoutConstraint动画?,ios,animation,Ios,Animation,当用户在我的iOS应用程序中滚动地图(类型为GMSMapView)时,我想设置按钮移动的动画: - (void)setButtonHidden:(bool)hidden [UIView animateWithDuration:1 animations:^{ [_myButton setAlpha:hidden ? 0 : 1]; // or so: [_myButtonConstraint setConstant:hidden ? -40

当用户在我的iOS应用程序中滚动地图(类型为
GMSMapView
)时,我想设置按钮移动的动画:

- (void)setButtonHidden:(bool)hidden
    [UIView animateWithDuration:1 animations:^{
        [_myButton setAlpha:hidden ? 0 : 1];
        // or so:
        [_myButtonConstraint setConstant:hidden ? -40 : 92];
        [[self view] layoutIfNeeded];
    }
}
显示动画的按钮可以完美地工作,但隐藏不会设置动画

我认为这是因为我从
mapView:willMove:
方法调用了
[self-setButtonHidden:YES]
,之后地图视图将被设置动画


如何组合不同的动画,在本例中为my animation和GMSMapView animation?

您可以组合动画,但
hidden
只需打开/关闭即可。 首先调整alpha(正如您所做的,但不使用hidden),并在完成块中设置hidden

[UIView animateWithDuration:1
                     animations:^{
                         _myButton.alpha = hidden ? 0 : 1;
                         // or so:
                        [_myButtonConstraint setConstant:hidden ? -40 : 92];
                        [[self view] layoutIfNeeded];
                     } completion:^(BOOL finished) {
                         _myButton.hidden = hidden ? YES : NO;
                     }];

您可以组合动画,但
隐藏
只需打开/关闭即可。 首先调整alpha(正如您所做的,但不使用hidden),并在完成块中设置hidden

[UIView animateWithDuration:1
                     animations:^{
                         _myButton.alpha = hidden ? 0 : 1;
                         // or so:
                        [_myButtonConstraint setConstant:hidden ? -40 : 92];
                        [[self view] layoutIfNeeded];
                     } completion:^(BOOL finished) {
                         _myButton.hidden = hidden ? YES : NO;
                     }];

我找到了解决办法。原因是

解决办法是:

dispatch_async(dispatch_get_main_queue(), ^{
    [UIView animateWithDuration:1 animations:^{
        [_myButton setAlpha:hidden ? 0 : 1];
        // or so:
        [_myButtonConstraint setConstant:hidden ? -40 : 92];
        [[self view] layoutIfNeeded];
        // or any other animation
    }];
});

谢谢大家的帮助

我找到了解决办法。原因是

解决办法是:

dispatch_async(dispatch_get_main_queue(), ^{
    [UIView animateWithDuration:1 animations:^{
        [_myButton setAlpha:hidden ? 0 : 1];
        // or so:
        [_myButtonConstraint setConstant:hidden ? -40 : 92];
        [[self view] layoutIfNeeded];
        // or any other animation
    }];
});

谢谢大家的帮助

谢谢,但结果是一样的。看起来
GMSMapView
中断了我的动画:(谢谢,但结果是一样的。看起来
GMSMapView
中断了我的动画:(您是否在没有alpha值的情况下进行了检查?是的,我尝试在没有alpha的情况下通过约束值设置移动动画。我后来添加了alpha值进行测试,但结果是相同的-隐藏不会设置0而不是-40的动画集,然后进行检查,然后我们可以找出它的布局问题还是其他问题?这是高度布局约束还是宽度?是相同的问题和n现在我试图通过
CAAnimation
解决我的问题,你检查了没有alpha值的情况吗?是的,我尝试了通过没有alpha值的约束值来设置移动动画。我后来添加了alpha值进行测试,但结果是一样的-隐藏不会设置0而不是-40的动画,然后检查,然后我们可以确定它的布局问题还是其他问题?是否存在这个高度布局限制或宽度?也是同样的问题,现在我试图通过
CAAnimation