Animation After Background Thread Complete (iOS / Swift)

971 views Asked by At

I'm looking to animate a few things when a long process (parsing) is complete. My barebones code currently looks like such:

func run_on_background_thread(code: () -> Void)
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), code)
}

func run_on_main_thread(code: () -> Void)
{
    dispatch_async(dispatch_get_main_queue(), code)
}

func manage_response()
{
    run_on_background_thread
    {
        long_process()
        run_on_main_thread
        {
            UIView.animateWithDuration(animation_duration, delay: 0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.8, options: UIViewAnimationOptions.CurveEaseInOut, animations:
                {
                    some_view.transform = CGAffineTransformMakeScale(0, 0)
                }, completion: nil)
        }
    }
}

Quite obviously, the animation does not occur. The UI just updates to the final stage. What is the proper way to thread this (I know animateWithDuration() dispatch's it's own thread, but I don't know how to hold this animation until the long process is complete.

Thanks.

1

There are 1 answers

3
Zhengjie On

I think U way can work. just change

some_view.transform = CGAffineTransformMakeScale(0, 0)

to :

some_view.transform = CGAffineTransformMakeScale(0.01, 0.01)

change the scale value close to zero; U can see the animation occur. if scale value == 0,there is no animation occur. U can try this.