5

Sometimes, interruptions such as phone call occur and disturb a regular behavior of an app in iPhone or iPad.

For example, I created one UIScrollView instance and implemented UIScrollView delegate methods: scrollViewWillBeginDragging and scrollViewDidEndDragging(and scrollViewDidEndDecelerating).

A scrollViewWillBeginDragging method deactivated all custom buttons in my app. Then scrollViewDidEndDragging and scrollViewDidEndDecelerating methods activated these custom buttons. That is, while the user scrolled, all custom buttons became deactivated for a while.

The problem was that while the user started to drag and just held an UIScrollView instance, if I took a screenshot by pressing a home button and a power button, then any of scrollViewDidEndDragging and scrollViewDidEndDecelerating didn't get called. So the app became messed up.

I implemented a UIApplicationWillResignActiveNotification method in my UIViewController, but it didn't get called after taking a screenshot.

How can I catch any kind of interruption that disturbs a regular flow of events?

Sometimes, touchesEnd and touchesCanceled didn't get called too due to an interruption.

Thank you.

pnmn
  • 1,127
  • 1
  • 14
  • 22
  • How about implementing viewWillAppear or viewDidAppear and testing if they get called after taking a screenshot? Then in those methods if (beingDragged == TRUE) call your scrollViewDidEndDragging method. – adam Jan 05 '11 at 15:18
  • viewDidScroll method also gets called even in interruptions? probably not and there you have an alternative approach to you problem. – nacho4d Jan 08 '11 at 13:57
  • I'm new to things, so I'm not sure why you'd disable a button when the user was using a different view? The impression I have from various readings is that the only time you'd want to disable a button is when it can't actually perform it's function because some bit of data is missing, i.e. no selection, or a field not filled in, etc. – Hack Saw Jan 11 '11 at 19:45

1 Answers1

2

I faced the same problem and got rid of it by using performSelector:withObject:afterDelay method of NSObject.

In scrollViewDidScroll:

[NSObject cancelPreviousPerformRequestsWithTarget:yourController];
[yourController deactivateButtons];
[yourController performSelector:@selector(activateButtons) withObject:nil afterDelay:0.5];

You can try this technique and combine it with other that you mentioned.
Hope, that will help. Good luck!

Zapko
  • 2,461
  • 25
  • 30