Loading xib depending on orientation of device whilelaunching the appliction

Joined
Jun 3, 2011
Messages
54
Reaction score
0
Points
6
Dear All

I have created login screen using IB. And in add-info.plist , in type: "main nib base file name", I have written name of the xib which I created using IB.

Now in application delegate's didFinishLaunchingWithOptions method, I am simply writing
[window makeKeyAndVisible];
return YES

This way, the login view (login xib)is loaded as soon as I start the application.But my problem is that this is always launched in portrait mode and there is no rotation when simulator/iPad is rotated.

My query is that If I make two xib: one for portrait mode and other for landscape mode, how is it possible to load the one depending on the device orientation.

Also, when I open the xib in IB, in attribute inspector, orientation of xib is always seen in default portrait (in orientation field) and I am unable to change it as it is disabled.

Any idea is appreciated.
Regards
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
I think you would be better off creating a UIViewController class, then loading the xib file from that controller class's initWithNibName:bundle: method.

That way you can use the UIViewController class's shouldAutorotateToInterfaceOrientation: method, like this.

Code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)io
{
    return (io == UIInterfaceOrientationPortrait || UIInterfaceOrientationIsLandscape(io);
}

The above implementation of the UIViewController method, will turn all views automatically
to the correct orientation.

Hope this helps.

Regards Mark
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top