Search code examples
iphoneobjective-cipaduipopovercontroller

issue with positioning of pop over view


When I am switching between Portrait to Landscape view (&Vice Versa) in iPad, position of my popover view gets garbled. Here is how I am calculating frame of my popover view:

aRect = self.myElement.frame;
aRect.origin.x += aRect.size.width;

[aPopOver presentPopoverFromRect:aRect inView:self.myElement.superview permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

Please tell me whats wrong here?


Solution

  • ok, i notice something weird about your code.

    any reason you are adding the size of the wide to the origin of aRect's x position? aRect.origin.x += aRect.size.width;

    im assuming you want this to be the top right corner....

    You can uncomment the code in your .m file and make it like so:

    // Override to allow orientations other than the default portrait orientation.
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
         Return YES; // for supported orientations
        //otherwise return (interfaceOrientation == UIInterfaceOrientationLandscape); if you want only landscape mode.
    }
    

    Or what i would do in your situation if you want to layout your subviews is use the didRotateFromIntferfaceOrientation: like so:

    (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        [self layoutSubviews];
    }
    

    and also layoutSubviews

    - (void)layoutSubviews
    {
        NSLog(@"layoutSubviews called");
    
        ...recalc rects etc based on the new self.view.bounds...
    }
    

    It works like so.

    PK