Adding iOS GUI to project


#1

Hi everyone

I’m having trouble adding a GUI to my iOS app. I’ve tried the following:

1 - Build new app using project generator.
2 - Add contents of iPhoneGuiExample/src/gui to new project
3 - Add the following to the top of ofApp.mm:

#include “MyGuiView.h”

MyGuiView * myGuiViewController;

void ofApp::setup(){
//Our Gui setup
myGuiViewController = [[MyGuiView alloc] initWithNibName:@“MyGuiView” bundle:nil];
[ofxiOSGetGLParentView() addSubview:myGuiViewController.view];
}

And these properties to ofApp.h (props referenced from MyGuiView):

float lengthRatio;
int numPoints;
bool bFill;

4 - Update MyGuiView.xib to open in latest Xcode and build for latest iOS
5 - Make sure .xib is added to Target / Build Phases / Copy Bundle Resources
6 - Check all the values in the inspectors (right side bar) when .xib is selected. File’s owner and view are linked. I noticed File’s owner / Identity Inspector / Class was “MyMusicView”. I changed this to MyGuiView. This didn’t help other than linkage warnings were removed.

The app builds fine and deploys to the device but the GUI is not displayed. Any thoughts on this?


#2

You could try to resize your view directly in your ofApp setup to check if it’s just a positioning problem, or something else:
[myGuiViewController setFrame:CGRectMake(0, 0, ofGetWidth(), ofGetHeight())];

To make it more visible you can also programmatically change your background color for debug:
[myGuiViewController.view setBackgroundColor:[UIColor colorWithRed:1.0 green:0 blue:0 alpha:1.0]];


#3

Thanks for the suggestions. Clearly something I should have tried before. It did not fix the problem though.


#4

Probably, if not a positioning problem, it might be that the setup is called before the ofView is added.

You could just add a minimum delay to see if that solves the problem:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.02 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
myGuiViewController = [[MyGuiView alloc] initWithNibName:@“MyGuiView” bundle:nil];
[ofxiOSGetGLParentView() addSubview:myGuiViewController.view];
}

If this doesn’t work you could try to add the gui view directly onto the UIWindow:

[ofxiOSGetUIWindow() addSubview: myGuiViewController.view];


#5

Amazing. Combining those 2 suggestions worked a treat. Thanks so much. I can now proceed with the rest of my life :slight_smile:

I wonder how the iPhoneGuiExample app manages to successfully add the MyGuiView to ofxiOSGetGLParentView() in ofApp:setup()?


#6

@jamesalliban

I wonder how the iPhoneGuiExample app manages to successfully add the MyGuiView to ofxiOSGetGLParentView() in ofApp:setup()?

It used to work exactly like that but stopped recently. My best guess is that there are some legacy settings somewhere that make it work. Does anyone know better?