简体   繁体   中英

UIView animateWithDuration start over

I have a simple question :) but I'm asking to gain benefits from awesome programmers in stackoverflow community.

I'm using UIView.animateWithDuration in my source view in viewDidAppear the animation start as follow by calling startTheStory():

override func viewDidAppear(animated: Bool) {

    if !animate {

        startTheStory()
    }
}

Then the view transaction with the destination view by using custom segue.

My problem is when the transaction start the animation in the source view start over so I tried to stop it by the following code:

override func viewWillDisappear(animated: Bool) {
    animate = true

    self.view.layer.removeAllAnimations()
}

But it doesn't work.

Also I tried in prepareForSegue() but it doesn't work.

Any idea?

Thanks

remove this line self.view.layer.removeAllAnimations()

and add these lines

[CATransaction begin]
[_backgroundView.layer removeAllAnimations]
[CATransaction commit]
[CATransaction flush]

Do remember to import QuartzCore/QuartzCore.h

Reason why your animation stars over is because

if !animate {

        startTheStory()
    }

is always executed in the viewDidAppear method, because the "animate" is set to false each time the view is about to paint again on the screen. Setting the "animate" to "True" in viewWillDisappear will get reset again to "False" when the viewDidAppear is called. So try to keep the "animate" var global in app delegate and set the value this should do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM