Mixing guis

Hi, I have a couple of questions about mixing JUCE and native IOS guis.

First question:
Where do I need to include the native IOS files in order to get the native stuff? I’m using the Introjucer for my projects (modules branch), so all project files have this in the beginning:

When I try to include a file like SomeFile.mm, which includes, let’s say, <UIKit/UIKit.h>, I get more than 1000 errors…

Second question:
Is it possible to embed a JUCE Component inside a UIScrollView?
If the answer is yes, then how can I do it?


Nevermind question 1… I did it.

This was niggling at me so gave it a go and yes, it is definitely possible, a little convoluted but this process could probably be simplified using a static helper method.

Simply create a UIScrollView in your xib file and an accompanying property in your view controller class’s header. Make sure you synthesize the property in your implementation and attach it from your ‘File’s Owner’ in Interface Builder to your UIScrollView.

Now you have to do a bit of Juce trickery to add your component to a UIView first. Create one with the size you want your content to be. Then add your component to the UIView you have just created, make it visible and set its bounds to that of the UIView. Then you need to update the UIScrollView’s contentSize property with your UIView’s bounds. Finally you need to add your UIView to to your UIScrollView.

The code might help make sense of that:

[code]@interface MainViewController : UIViewController
TextButton textButton;

@property (nonatomic, retain) IBOutlet UIScrollView* scrollView;


and in the implementation file:

[code]@implementation MainViewController

@synthesize scrollView;

  • (void)viewDidLoad
    [super viewDidLoad];

    UIView* contentUIView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, // x,y offset
    scrollView.bounds.size.width * 2, // content width
    scrollView.bounds.size.height * 2)]; // content height

    textButton.addToDesktop (0, (void*) contentUIView);
    textButton.setVisible (true);
    textButton.setBounds(contentUIView.bounds.origin.x, contentUIView.bounds.origin.y,
    contentUIView.bounds.size.width, contentUIView.bounds.size.height);

    scrollView.contentSize = contentUIViewForScrollToHold.bounds.size;

    [scrollView addSubview:contentUIView];
    [contentUIView release];


I’m not sure how this would react if you changed the scroll view’s size or the internal UIView’s size, you would probably have to update the component’s size as well. The other problem is that any transparency in Juce components seems to just be black, I haven’t really looked into this yet.

If you make any improvements to this let us know because mixing iOS and Juce is something I’m sure a lot of people want to do.

Thank you very much dave, this worked great!
I’ll keep you posted if I’ll get any improvements, I’m sure many others here would find it useful too.