Hold UIView or UIViewController on top of all the rest

I will subclass UIApplication to intercept and display strokes in my TouchDisplay view. I would like to extend Application, Window, Delegate or Main ViewController to keep the TouchDisplay view on top of all other views. Since mine and most other applications work, views and controllers are added and removed all the time. I believe that the correct answer will be able to cope with these additions and deletions, as well as maintain the top look of TouchDisplay.

Thanks for your help, Joe.

+4
source share
2 answers

Here are some approaches you could take to do this:

  • If you focus only on iOS 5+ and iPad, you can create a top-level controller that has two view controllers. The first would be a view controller for your "TouchDisplay" view. The second will be a regular application root controller. (i.e., the existing main presentation controller, you need to set the definePresentationContext parameter to YES on this presentation controller). Since you are writing a container view controller, you can order these two subtasks as you like. There is a WWDC 2011 Talk on the view controller> that details this. This is IMHO's most β€œcorrect” approach because it gives you a view controller for your TouchDisplay view, handles rotation, and usually plays well with others. (This only works on the iPad, because on the iPhone, the new modal look always covers the entire screen.)

  • A simpler approach is to simply add a TouchView to an existing top-level UIWindow as a subtitle with addSubview: . Most applications do not actually remove the top level controller or add new top levels; they simply represent other view controllers from it. The view that you add to the top-level window will remain higher. Of course, your application cannot follow this rule, in which case you can try option number 3 instead. This one has gotchas rotation (your gaze will not automatically rotate when the device rotates, so you need to do it yourself.) You can also get your gaze to go back up, say, to a 1 second timer if you have problems with other things covering it. This is also not as good as option # 1, because you are not getting a UIViewController, but only a UIView.

  • The most extreme approach is that you can create another UIWindow and give it a higher window level, such as UIWindowLevelAlert , and put a TouchDisplay view in it. You can then make the window a transparent background, and it will remain above the normal contents of the application. There are a lot of errors here, especially about auto-rotation, and which window is keyWindow (which is why you should use # 1 or # 2 if you can).

+4
source

After some time, I managed to get my application to work. I made an easy-to-use overlay that shows feedback regarding your existing application.

You can download the project here: https://github.com/megaplow/FingerTracks/tree/master/FingerTracks

Sample image

Happy coding, Joe

+2
source

All Articles