views:

51

answers:

1

Hi

I am new to objective-c and iPhone development but so far everything was going well til I tried to dig deeper (well not too deep). My problem is that I cannot initialize a specific UIView subclass with a specific coordinates for different orientations.

The rotation is working great but the problem is when the app initializes. I was thinking of giving a different layout for different orientation.

My app is actually an iPad app with a main UIViewController and three subviews (UIView s). lets call the view1, view2 and view3.

The three views are created on the project's nib and outlets are coded and connected for them.

The problem seems to be generating from the viewDidLoad method... it currently looks like this:

-(void)viewDidLoad{

    [super viewDidLoad];
    [view1 removeFromSuperview];
    [view2 removeFromSuperview];
    [view3 removeFromSuperview];

    UIInterfaceOrientation curOrientation = self.Orientation;

    if(curOrientation == UIInterfaceOrientationPortrait)
    {
       view1 = [[XView alloc] initWithFrame:CGRectMake(20,492,728,492)];
       view2 = [[YView alloc] initWithFrame:CGRectMake(384,20,364,472)];
       view3 = [[ZView alloc] initWithFrame:CGRectMake(20,20,364,472)];

       [self.view addSubview:view1];
       [self.view addSubview:view2];
       [self.view addSubview:view3];
    }
    else if(curOrientation == UIInterfaceOrientationLandscapeRight)
    {
      //Different coordinates
    }
    else if(curOrientation == UIInterfaceOrientationLandscapeLeft)
    {
     //Different Coodinates
    }

    }

My problem is that the views are not getting the same coordinates as the ones given in the viewDidLoad method and they seem to be initialized at x=0, y=0. However, when I rotate the device everything works like a charm and every UIView is set in its right place for each orientation. Basically I just call the setFrame method for each UIView.

I am not sure what am doing wrong here.... I need help...

Regards

A: 

Is your view the first view loaded in the app? I have found that in some cases the orientation could be marked as UIDeviceOrientationUnknown at first loads.

Anyway, it could be useful to see the rest of your class. Is your viewWillAppear changing the frame? has the self.view the right dimensions?

Angel García Olloqui