当用户在我的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]
,之后地图视图将被动画。
如何组合不同的动画,在本例中是我的动画和GMSMapView动画?
发布于 2017-03-10 15:55:02
我找到了解决方案。原因是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
}];
});
感谢大家的帮助!
发布于 2017-03-10 14:51:07
您可以组合动画,但hidden
只能打开/关闭。首先调整alpha (就像你做的那样,但不是隐藏的),然后在完成块中设置为隐藏。
[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;
}];
https://stackoverflow.com/questions/42711896
复制相似问题