Moving away from xib\nib

Member
Posts: 306
Joined: 2009.03
Post: #1
So I wanted to ditch xib\nib files because I am unable to detect touches under the status bar even though its invisible, and I read somewhere that you need to not use a xib\nib to get that to work. First off if anyone can confirm that, that would be great.

So here is what I did(note project based off of sample opengl project in xcode:

Code:
//In main changed the last 2 args from nil nil to:
int retVal = UIApplicationMain(argc, argv, @"UIApplication" , @"MyAppDelegate");

//in my app delegate applicationDidFinishLaunching added
rect.origin.x=0;
rect.origin.y=0;
rect.size.width=480;
rect.size.height=320;

window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  
window.backgroundColor = [UIColor whiteColor];  
[window makeKeyAndVisible];  
    
glView=[[EAGLView alloc] initWithFrame:rect];

[window addSubview:glView];

//In my EAGLView class duplicated constructor initWithCoder to
-(id)initWithFrame:(CGRect)rect
{
    if((self = [super initWithFrame:rect]))
    {
        // Get the layer
        CAEAGLLayer *eaglLayer = (CAEAGLLayer*) self.layer;
        
        eaglLayer.opaque = YES;
        eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:
                                        [NSNumber numberWithBool:FALSE], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil];
        
        context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
        
        if(!context || ![EAGLContext setCurrentContext:context] || ![self createFramebuffer])
        {
            [self release];
            return nil;
        }
    }
    return self;
}

While this gets my gl view on the screen, it is highly not how its supposed to look. It seems zoomed in for one, and there is a large blank area on the left side.
Does anyone have any experience with doing this?
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #2
To fix your code, just use UIScreen bounds for the everything - that made-up rect is rotated.

[EDIT]: This won't fix your touch problem though - that's a bug in the simulator - the device should work fine.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #3
You were right about both things. THanks.
Quote this message in a reply
Post Reply