iPad (simulator), rootViewController, frame, trouble

Status
Not open for further replies.
Here's a snippet of code:

Code:
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    self.window.rootViewController = self;
    CGRect wr = self.window.frame;
    CGRect vr = self.view.frame;
    vr = CGRectApplyAffineTransform(vr, vat);

wr is 768*1024, as it should be. vr, both before and after the transform, is 1216*1548.

Do you prefer tango or foxtrot? Or do you want to just drink whiskey all night?

It doesn't happen on iPhone, simulated or real.
 

Ember

Ars Centurion
346
Subscriptor++
First of all, why did you merge main view controller with app delegate. It's not prohibitted but I have never seen any source code doing this, from Apple or any other books I have read, but I find no benefit.
It's always better to make one class do one thing well not randomly merging many functionalities. And your class introduce circular reference, app delegate -> window -> main view controller (= app delegate), though app delegate and window will not be freed for the entire life of the app, it still is not a good object relations.

Second, I always use Xcode's project templates to make new project and if you select to create MainWindow.xib it contains main window and main view controller properly linked to app delegate. It's much easier and cleaner. All you have to do is the following code.
Code:
    [window addSubview:mainViewController.view];
    [window makeKeyAndVisible];
And it seems you don't need even above lines on iOS 5 (not 100% sure as I have not made iOS 5 only apps yet).
 

dawvee

Smack-Fu Master, in training
89
Where is the transform value (vat) in your snippet coming from? I realize that's probably not the issue though, since you've said that self.view.frame is identical before and after it's applied, but still curious.

The same as Ember's mentioned, most code I've seen doesn't make the UIViewController the app delegate. It occurs to me that that might mess up the controller's init and loadView methods. Those rely on UIScreen's applicationFrame property to initially size the view, but before the first app delegate message fires I'm not sure there are any guarantees on the return values of UIKit properties like applicationFrame. Using a nib would probably mask that issue, since the layouts are ultimately hard-coded, but doing it all dynamically in code could give you unpredictable initial values as a result.

Finally, why don't you just try assigning the window's frame to the view directly instead of trying to transform whatever value you're stuck with at launch?
 
I also think your view is screwed up. If you have done this all in code then you have no .xib for the view to come from. You also have no explicit initialisation of a view in code (that I can see), so where does it come from? In the app delegate the window replaces the view - if you look into the docs you see it is just a view subclass. I think if you run analyser you might get a warning about the state of the view, consider that when you create a UIViewController you must create a view by one method or the other. Also you don't use wr in that snippet so if it meant to be shown as part of the problem, that might be part of the problem if you know what I mean.
 

moonlina25

Seniorius Lurkius
1
Ember":3ot7ap0m said:
First of all, why did you merge main view controller with app delegate. It's not prohibitted but I have never seen any source code doing this, from Apple or any other books I have read, but I find no benefit.
It's always better to make one class do one thing well not randomly merging many functionalities. And your class introduce circular reference, app delegate -> window -> main view controller (= app delegate), though app delegate and window will not be freed for the entire life of the app, it still is not a good object relations.

Second, I always use Xcode's project templates to make new project and if you select to create MainWindow.xib it contains main window and main view controller properly linked to app delegate. It's much easier and cleaner. All you have to do is the following code.
Code:
    [window addSubview:mainViewController.view];
    [window makeKeyAndVisible];
And it seems you don't need even above lines on iOS 5 (not 100% sure as I have not made iOS 5 only apps yet).

very nice
 
Status
Not open for further replies.