Log in or register to post comments

Starting QCAR with a tabBarController

September 18, 2011 - 8:14am #1

Hello -Team,

Do not know if its possible hope you guys can point me in the right direction.

Currently i have an app which has a tabBarController that has 3 options.

The idea is that QCAR starts working when the user selects the second option of the menu QCAR (when the view for the second option is loaded).

- The tabBar should remain on the view after QCAR has started, and if i click on any of the other elements of the menu, QCAR should stop.

Thank you,

Re: Starting QCAR with a tabBarController

October 6, 2011 - 6:05pm #9

Hey -Team,

So as MoSR said, onResume() was missing.
Included the following on the posted code.

//- (void)viewWillAppear:(BOOL)animated
- (void)viewDidAppear:(BOOL)animated
{	
	[super viewDidAppear:animated];
	[viewEAGLView onResume];
}

If there is any room for improvement please advice, for now
Thanks all.

Re: Starting QCAR with a tabBarController

October 4, 2011 - 2:02am #8

The example provided by Omar tells you what's needed - look at the set up of EAGLview (the rotation and positioning).

The crucial thing you appear to be missing is the onResume() as shown in Omar's 'didSelectViewController'.

Put a break point or NSLog call in your renderFrameQCAR so you know when the system is ticking.

Re: Starting QCAR with a tabBarController

October 3, 2011 - 6:56pm #7

Hey guys,
So I keep working on this, I think I'm close let me know your thoughts.
Sorry for the long post, but I hope its clear where I am at.

In a nutshell what I have is:
1. Created a window file an named it MainWindow.xib
2. Inserted a Tab Bar Controller.
3. Included a Tab option which links to #4 view.
4. Created a UIViewControllerSubclass 'view1' which naturally creates the .h, .m and .xib

Done the following updates:

-In ImageTargetsAppDelegate.h/ImageTargetsAppDelegate.mm

#import <UIKit/UIKit.h>

@interface ImageTargetsAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
	UIWindow* window;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) IBOutlet UIViewController *view1;

@end

------

@synthesize window;
@synthesize tabBarController;
@synthesize view1;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
	BOOL ret = YES;
    
	self.window.rootViewController = self.tabBarController;
	[window makeKeyAndVisible];

	return ret;
}

*NOTE: included the releases.

-In View1.h/View.mm

#import <UIKit/UIKit.h>
#import "EAGLView.h"

@interface View1 : UIViewController {
	View1 *view1;
	EAGLView *viewEAGLView;
}

@property (nonatomic, retain) IBOutlet EAGLView *viewEAGLView;
@property (nonatomic, retain) IBOutlet View1 *view1;

@end

------

*Note: tried also with viewDidAppear, viewWillAppear:

- (void)viewDidLoad
{
	[super viewDidLoad];
	// Do any additional setup after loading the view from its nib.
	
	CGRect viewBounds;
	viewBounds.origin.x = 20;
	viewBounds.origin.y = 20;
	viewBounds.size.width = 200;
	viewBounds.size.height = 280;
	viewEAGLView = [[EAGLView alloc] initWithFrame: viewBounds];
	
	viewEAGLView.backgroundColor = [UIColor blueColor];
	// added color just to test that it's actually showing
	 
	self.view.backgroundColor = [UIColor greenColor];
	// added color just to test that it's actually showing
	
	[self.view addSubview: viewEAGLView];
	[viewEAGLView onCreate];
}

Included alerts in the different methods of EAGLView.mm, just to keep track, for example: onCreate, initQCAR, startCamera...

Visually on the device im seeing the tab bar menu, an the green background with a blue rectangle (what i think its the EAGLView frame) an also the mentioned alerts.
* When i click on the blue box the QCAR menu shows.
* What I'm missing is to get the video shown.

Any advice or suggestions?
Am I on the wrong path, is it possible what I'm trying to achive?

see Images attached.
Thanks MoSR and Omar,

Re: Starting QCAR with a tabBarController

September 29, 2011 - 2:32am #6

Thanks for sharing that Omar.

Re: Starting QCAR with a tabBarController

September 28, 2011 - 10:32am #5

Hi Victor,

I've experimented with this before. Below is my code (I never used this code in an app, so it will need to be tested further). It should be clear how to do this from a XIB too, just reference your elements in the header file.

This is using the ImageTargets sample app as a template. First ImageTargetsAppDelegate needs to implement the UITabBarControllerDelegate, this is what it looks like:

#import <UIKit/UIKit.h>
#import "EAGLView.h"
#import "OverlayView.h"
#import "OverlayViewController.h"


@interface ImageTargetsAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
    UIWindow* window;
    OverlayViewController* overlayViewController;
    OverlayView* overlayView;
    EAGLView* view;
    UIViewController *firstViewController;
    UIViewController *secondViewController;
    UITabBarController *tabBarController;
}

@property(nonatomic, retain)UITabBarController *tabBarController;

@end

The implementation:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    CGRect screenBounds = [[UIScreen mainScreen] bounds];
    
    window = [[UIWindow alloc] initWithFrame: screenBounds];
    
    // We are going to rotate our EAGLView by 90 degrees, so its width must be
    // equal to the screen's height, and height to width
    CGRect viewBounds;
    viewBounds.origin.x = 0;
    viewBounds.origin.y = 0;
    viewBounds.size.width = screenBounds.size.height;
    viewBounds.size.height = screenBounds.size.width;
    view = [[EAGLView alloc] initWithFrame: viewBounds];
    
    // Create an auto-rotating overlay view and its view controller (used for
    // displaying UI objects, such as the camera control menu)
    overlayView = [[OverlayView alloc] initWithFrame: screenBounds];
    overlayViewController = [[OverlayViewController alloc] init];
    [overlayViewController setView:overlayView];
    
    firstViewController = [[UIViewController alloc] init];
    firstViewController.view = view;
    [firstViewController.view addSubview:overlayViewController.view];
    firstViewController.title = @"QCAR";
    
    secondViewController = [[UIViewController alloc] init];
    secondViewController.view.backgroundColor = [UIColor blueColor]; // blue just to test that it's actually showing
    secondViewController.title = @"Other view";
    
    tabBarController = [[UITabBarController alloc] init];
    tabBarController.viewControllers = [NSArray arrayWithObjects:firstViewController, secondViewController, nil];
    tabBarController.delegate = self;
    
    // Set the EAGLView's position (its centre) to be the centre of the window
    CGPoint pos;
    pos.x = screenBounds.size.width / 2;
    pos.y = (screenBounds.size.height / 2);
    [[view layer] setPosition:pos];
    
    // Rotate the EAGLView by 90 degress (landscape to portrait)
    CGAffineTransform rotate = CGAffineTransformMakeRotation(90 * M_PI  / 180);
    view.transform = rotate;
    overlayView.transform = CGAffineTransformMakeRotation(-90 * M_PI  / 180); // I can't remember why I did this, I think it's so that the touch actions are received properly
    
    [window addSubview:tabBarController.view];
    [window makeKeyAndVisible];
    
    // Perform actions on the EAGLView now it has been created
    [view onCreate];
    
    return YES;
}

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    if (viewController == firstViewController) {
        [view onResume];
    } else {
        [view onPause];
    }
}

In OverlayView.mm need to change the actionsheet so that it works with a tab bar controller, there's probably a better way of doing this, but this is how I did it:

#import "ImageTargetsAppDelegate.h"
....
....

//[actionSheet showInView:self];
[actionSheet showInView:((ImageTargetsAppDelegate *)[[UIApplication sharedApplication] delegate]).tabBarController.view];

Re: Starting QCAR with a tabBarController

September 27, 2011 - 2:17am #4
victorduarte wrote:

I am not able to make my EAGLview one of the views within the UITabBarController (.xib).

Could you give me guidance on this subject?

Hi Victor, I'll try out this scenario when I next have a spare slot - unless somebody with experience of this construct can step in to advise you.

Re: Starting QCAR with a tabBarController

September 26, 2011 - 1:59pm #3

Hello MoSR,

I have been on this with no luck, i am not able to make my EAGLview one of the views within the UITabBarController (.xib).

Could you give me guidance on this subject?

Thank you in advance.

Re: Starting QCAR with a tabBarController

September 19, 2011 - 3:24am #2

http://ar.qualcomm.at/node/2000738

In your use case, your EAGLview should be one of the views within the UITabBarController, either in the .xib or inserted dynamically. You can load QCAR in the app initialisation as in the sample apps, or manage the lifecycle yourself.

This should give you enough guidance to achieve what you want.

Log in or register to post comments