animateWithDuration stops animate - iphone

My code uses animateWithDuration in few places.
Everything works fine and the animation plays alright for a while, but - sometimes the screen suddenly freezes for half second and all the animation in all views stops play.
Means - the objects animation effected, but it ignores the duration or delay parameters.
I really guess it is up to some background processes, but I am really not sure about it.
In some places in code I use animateWithDuration inside methods that run under performSelectorOnMainThread, but it does not make a difference.
I'd be glad to hear ideas of why it happens and how to fix it.
Thanks in advance.

Related

Animation in Unity is repeated 2 times

I have an animation which plays when I activate trigger "shoot". When it activate, animation plays 2 times. If I change Transition duration, it either it is not played at all, or it is played twice.
Pls, help me. I work on Unity 2020.3.0f1. My english is not very well, sorry
UPD: OMG I find a path to fix it. You need to check is your animation running, and if it isnt - you can run it. Use GetCurrentClipInfo
Maybe your animation is on loop. Check that.

Delegate Method only Firing after 5 or so Button Presses?

I'm having the most bizarre problem which I'm not even close to figuring out. I have a button which fires a delegate method. Once upon a time it was working fine, but after making some changes to my code, now the delegate method only fires after I push the button x amount of times (the changes I made to the code had nothing to do with the infrastructure that connects the delegate together). It varies, it can be 5 times to 10 times. I used the analyzer to check for memory leaks and there aren't any.
There is too much code for me to paste here (I don't even know where to start or where the problem could be), but I'm wondering if anyone has experienced this problem before, or what could be causing it? This is very odd and have no clue what could be causing it.
sounds like some other view is getting the touch events over the button. I've also seen this type of behavior when the touch area is too small (either because the button is too small or because it's getting clipped by another view)

iPhone Pause CAAnimation from app enter background and retrieve

I've been reading functions of how to pause CAAnimation at:
https://developer.apple.com/library/ios/#qa/qa2009/qa1673.html
And it works great! Apart from when I tap the home button to make the app to background(which I did use the same pause technique for applicationWillResignActive)
However, it happens that the animation seems completely erased rather than its nice pausing.
Any suggestion of how to solve this issue?
It sometimes also happens that the storyboard seems restart the entire app from beginning?
I've used the technique from that link to pause animations and it works perfectly.
However, based on a little testing, it looks to me like the system kills running CAAnimations when your app goes to the background. If you want to resume the animation where it left off, you would have to recreate the animation(s) and set the beginTime parameter to a value that offsets into the animation. I haven't done that, so I couldn't tell you exactly how to do it without doing some tinkering.

Blocking on UIImageView animation, or, "while not finished animating, spin"

I'm currently animating many images via 4 UIImageViews, and all is well on that front. The animations complete as expected, and I am assuming that they run inside their own NSThread, as execution continues despite the animation. Of course, this is good and expected behaviour, as I definitely wouldn't want my whole app to halt until the animation finishes.
However, I need to kick off a method which needs to depend on whether the animation is running or not.
The following code is bad as I understand, as introducing loops and other delays inside the main thread causes instability.
while([self.fooImgView isAnimating])
;
This code effectively halts execution of the whole app. I need to find a way to "spin" until the animation completes, without wedging the app.
Any advice on this would be greatly appreciated.
Thanks!
sc.
If you use block animations like this one, you can use the completion block to call some delegate or execute your method

Does it help to start intensive core animation blocks in another thread?

I have an scroll view with some sophisticated animations happening during scrolling. Although after 2 weeks of finetuning the performance is acceptable now, the scrolling is not 100% smooth when the animations happen.
I know that core animation does animations in a background thread. But I wonder if it would help to split those animation blocks (10 of them at pretty much the same time) into threads.
There are a few methods that look interesting:
– performSelector:onThread:withObject:waitUntilDone:
– performSelectorInBackground:withObject:
or is that nonsense to do?
No, it won't help. As you correctly stated yourself, Core Animation already runs in a seperate thread. Core Animation is smart enough to handle animation blocks as efficiently as possible. I wouldn't advise interfering with it.
The Core Animation Programming Guide says:
An abstract animation interface that
allows animations to run on a separate
thread, independent of your
application's run loop. Once an
animation is configured and starts,
Core Animation assumes full
responsibility for running it at frame
rate.
Are you sure the choppy behavior is really from CA? Do you have anything else going on?
If you have any background network access, consider moving that into a separate thread - the time taken to service those calls takes away from time the UI spends updating the screen as you scroll.