gpt4 book ai didi

ios - 当 GMSMapView 移动时,如何为 NSLayoutConstraint 设置动画?

转载 作者:行者123 更新时间:2023-11-28 21:11:56 25 4
gpt4 key购买 nike

我想在我的 iOS 应用程序中为用户滚动 map (类型为 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],之后 map View 将被动画化。

如何组合不同的动画,在本例中是我的动画和 GMSMapView 动画?

最佳答案

我找到了解决方案。原因是 GMSMapView bug

解决方法是:

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
}];
});

谢谢大家的帮助!

关于ios - 当 GMSMapView 移动时,如何为 NSLayoutConstraint 设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42711896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com