Create transparent UIView to handle touch input

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
el3ktro
Gnoblar
Posts: 5
Joined: Wed Jul 07, 2010 12:06 am

Create transparent UIView to handle touch input

Post by el3ktro »

Note: I've read all the other posts about this, but nothing worked for me.

My CEngine.cpp is basically the one from the Ogre template. I have a separate AppDelegate.m with a -applicationDidFinishLaunching method, which currently looks like this:

Code: Select all

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{
	[[UIApplication sharedApplication] setStatusBarHidden:YES];
	
	mLastFrameTime = 1;
	
	UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
	
	viewController = [[UIViewController alloc] initWithNibName:nil bundle:nil];
	touchReceiver = [[TouchReceiverView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
	
	[touchReceiver setBackgroundColor:[UIColor clearColor]];
	[touchReceiver setOpaque:NO];
	[viewController setView:touchReceiver];
	[touchReceiver release];
	
	[window addSubview:viewController.view];
	[window makeKeyAndVisible];
	[viewController release];
	
	[self go];
}
I see my Ogre scene and I see the view above it (the custom view I've created has a label in it, which is shown above the Ogre scene). Sohaving a transparent view above the Ogre scene works - but it doesn't catch any touch events. When I comment out the [self go] it catches the touch events (I've checked by letting -touchesBegan: output to the console log) but as soon as I start Ogre it won't work. I've already tried becomeFirstResponder on the view - didn't work.

Can anybody tell me what I have to do so that all touches are handled by my custom UIView and not by Ogre?
User avatar
petrocket
Gremlin
Posts: 178
Joined: Tue Mar 20, 2007 3:29 am
x 10

Re: Create transparent UIView to handle touch input

Post by petrocket »

This is what my applicationDidFinishLaunching looks like:

Code: Select all

- (void)applicationDidFinishLaunching:(UIApplication *)application
{
    // Hide the status bar
    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    
    mDisplayLinkSupported = FALSE;
    mLastFrameTime = 1;
    mStartTime = 0;
    mTimer = nil;

    // A system version of 3.1 or greater is required to use CADisplayLink. The NSTimer
    // class is used as fallback when it isn't available.
#if USE_CADISPLAYLINK
    NSString *reqSysVer = @"3.1";
    NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
    if ([currSysVer compare:reqSysVer options:NSNumericSearch] != NSOrderedAscending)
        mDisplayLinkSupported = TRUE;
#endif

    [self go];
    
    // Create the window, it's not created without a nib
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    // Create a subview that is clear
    TouchView *myView = [[TouchView alloc] initWithFrame:[self.window bounds]];
    [myView setBackgroundColor:[UIColor clearColor]];
    
    // Add the subview and release the memory, sicne the window owns it now
    [self.window addSubview:myView];
    [myView release]; 
    
    [self.window makeKeyAndVisible];
    
}
Ogre API & Manual | Ogre Wiki

blog | website | work

Follow me on twitter @ twitter.com/petrocket
rado0x54
Gnoblar
Posts: 14
Joined: Fri Jul 08, 2011 5:38 pm
x 1

Re: Create transparent UIView to handle touch input

Post by rado0x54 »

You can also add the Gesture Recognizer directly to the EAGL2 view.

Code: Select all

    Ogre::RenderWindow *mWindow = Ogre::Root::getSingleton().getAutoCreatedWindow();
    UIWindow *mUIWindow = nil;
    mWindow->getCustomAttribute("WINDOW", &mUIWindow);
    UIViewController *EAGL2vc = mUIWindow.rootViewController;

    // START GESTURES
    self.gc = [[GestureBridge alloc] init];
    self.gc.eagl2View = EAGL2vc.view;
    UIGestureRecognizer *pangr = [[UIPanGestureRecognizer alloc] initWithTarget:gc action:@selector(pan:)]; 
    [EAGL2vc.view addGestureRecognizer:pangr];
    [pangr release];
    
    UIGestureRecognizer *rotationgr = [[UIRotationGestureRecognizer alloc] initWithTarget:gc action:@selector(rotation:)]; 
    [EAGL2vc.view addGestureRecognizer:rotationgr];
    [rotationgr release];
    
    
    UIGestureRecognizer *pinchgr = [[UIPinchGestureRecognizer alloc] initWithTarget:gc action:@selector(pinch:)]; 
    [EAGL2vc.view addGestureRecognizer:pinchgr];
    [pinchgr release];
    // END GESTURES