0

The code is too huge to post it here. My problem is the following. When I call animateWithDuration:animations:completion: (maybe with options) with duration == 0.3 it doesn't mean that the completion block will be called through the same delay. It is called through 2 seconds instead and it is too long for me.

This big delay usually appears before memory warnings but sometimes may work as expected.

Could anybody explain what may cause such a strange behaviour?

Vyachaslav Gerchicov
  • 2,317
  • 3
  • 23
  • 49
  • Sorry With no code its really hard to figure out . Taking a shot in a dark is unpredicatble so will be the answer too ....... – sriram hegde Jul 29 '15 at 14:52
  • I hoped there could be some common reasons. Such as "memory leaks usually appear when you allocate memory for objects but forget to release it" – Vyachaslav Gerchicov Jul 29 '15 at 14:55
  • You may have something blocking the mainthread/UI meanwhile you're doing the animation. – Larme Jul 29 '15 at 14:56
  • My hands are tied here buddy :) – sriram hegde Jul 29 '15 at 14:57
  • 1
    Vyachaslav - Sadly, no, there aren't "common" reasons for completion block problems. Either you're trying to do some UI stuff from some background thread, or you're doing something that's blocking the main thread. You should create [MCVE](http://stackoverflow.com/help/mcve), the simplest possible example that manifests the problem you're describing. That's the only way we can help you (and often, you'll discover the source of the problem yourself in the process of creating the MCVE). – Rob Jul 29 '15 at 15:10
  • It seems I have found the reason. I'm not sure but the app I develop has a lot of `UIWebView` objects. `loadRequest:...` is called asynchronously but can its `drawRect:` slow down the main thread as you wrote? – Vyachaslav Gerchicov Jul 30 '15 at 14:07

3 Answers3

0

Are there any timers involved, like is the animation timer-triggered? I had a similar problem when my animation was timer-triggered. It turned out the animation was started more than once. animationOngoing flag stopped animation from being started again before finishing.

// Timer function
    func timerTextToggle(timer: NSTimer) {
    if self.animationOngoing == false {
        self.flipAnimation()
    }
}

// Animation function
func flipAnimation() {
// important note: it's UIViewAnimationOptions,
// not UIViewAnimationTransition
    self.animationOngoing = true
    if self.animationToggle == false {
        UIView.transitionFromView(self.singleTapLabel!,
            toView: self.doubleTapLabel!,
            duration: animDuration,
            options: UIViewAnimationOptions.TransitionFlipFromBottom,
            completion: {
                (value: Bool) in
                self.animationOngoing = false
        })
    } else {
        UIView.transitionFromView(self.doubleTapLabel!,
            toView: self.singleTapLabel!,
            duration: animDuration,
            options: UIViewAnimationOptions.TransitionFlipFromTop,
            completion: {
                (value: Bool) in
                self.animationOngoing = false
        })
    }
    self.animationToggle = !self.animationToggle
}
Thorory
  • 1
  • 2
  • Sorry, I can't understand what does you you mean. Could post any example? Maybe the `RZViewActions` library has influence on it. It allows simultaneous animations but it can't cause this problem by itself because the demo works normally. – Vyachaslav Gerchicov Jul 29 '15 at 15:27
  • No, I don't use `NSTimer` via this way. Maybe some extra calls of `performSelector:...` have the similar effect. I'll write if I'll found the reason – Vyachaslav Gerchicov Jul 30 '15 at 09:18
0

I experienced a similar problem to this, although without further information on your scenario, I don't know if this also applies to your issue.

I was calling becomeFirstResponder on a UITextField in the completion block of my animateWithDuration:delay:options:animations:completion. Logging showed the completion block was being called in a timely manner, but the keyboard was taking several seconds to show. This was only occurring on first launch of the keyboard.

This answer helped me solve this... turned out this was somehow linked to the iOS Simulator. This issue did not occur when I wasn't debugging the app... another classic example of chasing a bug for hours in the simulator that didn't actually exist.

Community
  • 1
  • 1
jt_uk
  • 1,362
  • 1
  • 15
  • 17
0

The cause of this problem is found out. It is a lot of UIWebView objects rendered in the main thread. And it seems impossible to prevent their loading. Anyways time profiler show that a lot of time is spent to render them even if they are not visible on the screen. And yes, I can't release them before memory warning event because of requirements

Vyachaslav Gerchicov
  • 2,317
  • 3
  • 23
  • 49