views:

233

answers:

2

I needed to see touch events on my window, so I subclassed UIWindow to make my a MYWindow class. I am overriding the sentEvent function to receive the touch events on the window and all of that is working just fine. I did the following to achieve this:

self.window = [[MYWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window makeKeyAndVisible];

The issue I am facing is that when I do this, the viewControllers that are on this window won't rotate anymore. If I were to use a regular UIWindow, they all work just like I intended them to work. Obviously, something is wrong with my setup.

I was looking through UIWindow header file and there is a method called

- (void)becomeKeyWindow;  //override point for subclass, Do Not call directly

Am I suppose to implement this in my custom UIWindow class just like I had to implement the sendEvent: method? Please point me in the right direction with this.

Thanks in advance guys.

A: 

I'm only guessing here, but I'd presume it is because you made MYWindow the key window now (even if it is transparent) and shouldAutorotateToInterfaceOrientation: is part of UIViewController class, not UIWindow.

So even though you can see your other views, they are not getting their rotation events called on them anymore.

Instead of making it a UIWindow subclass, why not implement those touch events on a UIView that gets added to your view that needs the touch events handled? You can make it transparent as well, and just keep the rotation handled at the UIViewController level?

iWasRobbed
the reason I have subclassed the UIWindow is I have a password screen that shows up after a certain while if no activity (touches) are detected on the screen. To accomplish that, I subclassed the sendEvent function to detect any touch on any of the viewControllers. I didn't want to repeat this same code in every single one of my viewControllers. Had it been that I only needed the touch event on one viewController, I would have done that. However, thats not the case. Every other functionality is called just fine. I have go in and out of viewControllers without any issue.
Bittu
You look into seeing if you can pass motion events as well. Apple has some guidance on this, but I've never done it, so I'm not sure if you can pass anything other than accelerometer data which you would then have to interpret yourself.
iWasRobbed
A: 

I figured out what the issue was. I was creating a delegate on the custom window and called it "delegate" which was causing the issue. Naming it to "aDelegate" solved the issue. thanks for all your help.

Bittu