iPhone Mapkit:图钉一一掉落

发布于 2024-09-12 13:39:20 字数 258 浏览 5 评论 0原文

我正在使用 mkmapview 并在其上放置图钉。我希望销钉一根一根地落下,而不是同时落下。最初我正在调用

[self performSelector:@selector(dropPin) withObject:nil afterDelay:dropTime];

其中 dropTime 是每个引脚的不同延迟,而 dropPin 是一种使引脚下降的方法。不幸的是,这背后的多线程似乎会导致崩溃。

有谁知道更好的方法吗?

I'm using an mkmapview and dropping pins on to it. I would like the pins to fall one by one, rather than all simultaneously. Originally I was calling

[self performSelector:@selector(dropPin) withObject:nil afterDelay:dropTime];

where dropTime was a different delay for each pin, and dropPin was a method to make the pin drop. Unfortunately the multithreading behind this seems to cause a crash.

Does anyone know a better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别把无礼当个性 2024-09-19 13:39:20

如果您的目标是 iOS4,块是处理动画的好方法,而无需担心委托、回调或选择器:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
    if ([views count] == 0) {
        return;
    }
    MKAnnotationView *aV;
    for (aV in views) {
        // set up pin beginning and end frames, shadow subview frame and center

        [UIView animateWithDuration:0.75
                              delay:(0.0 + [views indexOfObject:aV]/10.0)
                            options:UIViewAnimationOptionCurveEaseOut
                         animations:^{
                             [aV setFrame:endFrame];
                             // animate the shadow subview's center point
                         }
                         completion:^ (BOOL finished) {
                            if (finished) {
                                // do something here when the animation finished
                            }
                         }];
}

If you're targeting iOS4, blocks are a great way to handle animations without worrying about delegates, callbacks, or selectors:

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
    if ([views count] == 0) {
        return;
    }
    MKAnnotationView *aV;
    for (aV in views) {
        // set up pin beginning and end frames, shadow subview frame and center

        [UIView animateWithDuration:0.75
                              delay:(0.0 + [views indexOfObject:aV]/10.0)
                            options:UIViewAnimationOptionCurveEaseOut
                         animations:^{
                             [aV setFrame:endFrame];
                             // animate the shadow subview's center point
                         }
                         completion:^ (BOOL finished) {
                            if (finished) {
                                // do something here when the animation finished
                            }
                         }];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文