Run a sketch on top of a UIView?

Hi all,

I’ve built this app in the style of iPhoneGUIExample, where the UI is built in Objective-C/IB and the code is running in openframeworks. I want to be able to swipe to switch background images, with the sketch running on top of it. The other thing is that I have some UI controls that need to run on top of the sketch, so the sketch really needs to be in between the background image and the controls. I’m sure I can probably hack some OF code into the sketch to get the swiping/background switching done, but so far I haven’t needed to go there and would prefer not to if necessary. Does anyone have any ideas, or should I just write this feature in OF alone? Thanks!

Josh

Sure thing. Include your ViewController in TestApp.h and declare it:

  
  
#include "MyViewController.h"  
MyViewController *viewController;  
  

Then in your implementation file setup function, load your UI from the .XIB file:

  
   
NSString *nibName = @"MyView";  
viewController = [[MyViewController alloc] initWithNibName:nibName bundle:nil];  
  

Finally, add the view to your main GL View (also in setup()):

  
  
[ofxiPhoneGetGLView() addSubview:viewController.view];  
  

Make sure you make your view Multiple Touch enabled, and now you can add buttons to your view and they will show on top of your oF project, with all touches that are not on buttons or other UI items getting properly captured by the oF view.