animateWithDuration 在 GMSMapView 委托方法中不起作用 [英] animateWithDuration not working inside GMSMapView delegate method

查看:26
本文介绍了animateWithDuration 在 GMSMapView 委托方法中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用下面的代码为 UIView 设置动画,但我不明白为什么下面的代码不起作用.

I am trying to animate a UIView with the code below, but I fail to understand why the code below does not work.

作品 - self.searchBar 动画流畅//除了上述方法

Works - self.searchBar animates smoothly // in all except for the said method

- (void) mapView:(GMSMapView *)mapView idleAtCameraPosition:(GMSCameraPosition *)position
{
    [UIView animateWithDuration:.3
                          delay:0
                        options: UIViewAnimationCurveEaseOut
                     animations:^{

                         [self.searchBar setFrame:CGRectMake(self.searchBar.frame.origin.x, self.searchBar.frame.origin.y - self.searchBar.frame.size.height  , self.searchBar.frame.size.width, self.searchBar.frame.size.height)];
                     }
                     completion:^(BOOL finished){
                     }];
}

不起作用 - self.searchBar 在没有动画的情况下跳转

Does Not Work - self.searchBar jumps without animating

- (void)mapView:(GMSMapView *)mapView willMove:(BOOL)gesture
{
        [UIView animateWithDuration:.3
                              delay:0.0
                            options: UIViewAnimationCurveEaseOut
                         animations:^{

                             [self.searchBar setFrame:CGRectMake(self.searchBar.frame.origin.x, self.searchBar.frame.origin.y - self.searchBar.frame.size.height  , self.searchBar.frame.size.width, self.searchBar.frame.size.height)];

                         }
                         completion:^(BOOL finished){
                         }];
}

推荐答案

我在 Google 上打开了有关此问题的错误 (https://code.google.com/p/gmaps-api-issues/issues/detail?id=10349),这是他们的回复:

I opened a bug on this issue with Google (https://code.google.com/p/gmaps-api-issues/issues/detail?id=10349), and this was their response:

我们的理解是,这是因为 mapView:willMove: 调用是在 CoreAnimation 事务中进行的.我们建议的解决方法是将 UIView.animateWithDuration 调用在 dispatch_async 中包装回主线程.类似的东西:

Our understanding is that this is happening because the mapView:willMove: call is being made while already inside a CoreAnimation transaction. Our suggested work around is to wrap the UIView.animateWithDuration call within a dispatch_async back to the main thread. Something along the lines of:

dispatch_async(dispatch_get_main_queue(), ^{//动画块在这里.});

dispatch_async(dispatch_get_main_queue(), ^{ // animation block here. });

这有帮助吗?

将 UIView.animateWithDuration 块放在 dispatch_async 块内对我有用.

Placing the UIView.animateWithDuration block inside a dispatch_async block worked for me.

此外,这个问题与 iOS 布局动画在 GMSMapView 拖动时会忽略持续时间,但我没有足够的代表将其标记为这样.如果有人记分,还应该注意的是,谷歌的解决方法是毗湿奴在他的回答中建议的.我也没有足够的代表来评论他的回答.

Also, this question is a duplicate of iOS layout animation ignores duration when fired on GMSMapView dragging, but I don't have enough rep to flag it as such. If anyone's keeping score, it should also be noted that Google's workaround is what Vishnu suggested in his answer. I didn't have enough rep to just comment on his answer either.

这篇关于animateWithDuration 在 GMSMapView 委托方法中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆