0

Is there any possible way to detect every change on User Interface during runtime??

I'm trying to find all objects in the current app interface.

I'm trying to to get all nodes inspecting recursively the main Window, but, for example, how to know if the top viewcontroller changes or if it's added a uiview dynamically, or is presented a modalview??

The main objective is to have a library to do this..

Any idea, help?

Thanks!

Frade
  • 2,938
  • 4
  • 28
  • 39

1 Answers1

0

You could write your own library based on this, using advanced Objective-C techniques. I do not recommend you to do this, since it mostly breaks MVC patterns on iOS. Depends on what do you want to use it for, maybe analytics?

So these are the options I believe, if you want to actively inspect UIView hierarchy. All options are pretty complicated though.

  • Swizzle methods such as addSubview and removeFromSuperview of UIView, so you could know when changes like that happens. Including the getters of frame and bounds, if you wish to know the position.

  • You could use KVO to watch properties such as: subviews, frame, bounds, superview to notice any changes. But at one point you would have to add the same object as the observer (could be singleton).

  • Decide for an interval that is fired by a NSTimer and go through the hierarchy recursively beginning at keyWindow on UIApplication. This would have a big performance impact though.

There may be other options, but these are the ones I believe to be the best choices.

Legoless
  • 10,942
  • 7
  • 48
  • 68
  • I already tried add an observer to window subviews property. No luck, observeValueForKeyPath is not called.. – Frade Apr 11 '14 at 14:48
  • Question http://stackoverflow.com/questions/6612523/ios-how-do-i-know-if-a-property-is-kvo-compliant explains a bit more about KVO in `UIKit`. Apparently not a very good idea. Swizzling would be the next thing to try. – Legoless Apr 11 '14 at 14:58