0

In My iphone Application,I am doing simple image animation in a View and in that same View i have WebView in which i am showing HTML.i have done that animation by making the infinite calls of my animation code(animationMethodA),i am doing this by setting the NSTimer.My Problem is that when i scroll the WebView then same time That animating Image get stopped and that animating image remains in rest stage(stopped) until i stopped scrolling the webView.As i stop Scrolling the WebView Animation starts itself.Actually i got the Reason of that Problem.at the time of scrolling the WebView time(NSTimer) not call that animationmethodA method.

Please let me What should i do for that problem?.

Thanks.

Kamar Shad
  • 6,089
  • 1
  • 29
  • 56

1 Answers1

1

Finally i got the Solution for my Question.

I have to add the timer to another RunLoopMode, Per default a timer is added to the NSDefaultRunLoopMode. That means that the timer is only executing when the app’s run loop is in NSDefaultRunLoopMode.

Now, when a user touches the screen (e.g. to scroll a UIScrollView) the run loop’s mode will be switched to NSEventTrackingRunLoopMode. And now, that the run loop is not in NSDefaultRunMode anymore, the timer will not execute. The ugly effect of that is, that timer is blocked whenever the user touches the screen. And that can be a long time when the user is scrolling, because the timer is blocked until the scrolling completely stops. And when the user continues to scroll, the timer is blocked again.

Fortunately the solution to this problem is quite simple: You can add your timer to another NSRunLoopMode. When add the timer to NSRunLoopCommonModes it will execute in all run loop modes (that have been declared as a member of the set of “common” modes, to be precise). That means that the timer is not only working in NSDefaultRunLoopMode but also in NSEventTrackingRunLoopMode (when the user touches the screen).

So after you initialize your timer, add it to NSRunLoopCommonModes:

[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];

I got this answer form this link

I hope this may helpful to someone...!!!

Community
  • 1
  • 1
Kamar Shad
  • 6,089
  • 1
  • 29
  • 56