Question

i am having little problem here. I have made a popout view activated on toolbard button click. However the view is not in the position i want. See screenshot
1st screen shows what i have and 2nd what i want. btw: popview is done problematically. No xib or storyboard involved.
enter image description here

Some code

 -(IBAction)addbutton:(UIToolbar *)sender;
{
        //build our custom popover view
    UIViewController* popoverContent = [[UIViewController alloc]
                                        init];
    UIView* popoverView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
    popoverView.backgroundColor = [UIColor blackColor];

    /*
     * Adding buttons programaticly to popout view
     * button code etc 
     */ 
    popoverContent.contentSizeForViewInPopover = CGSizeMake(400, 300);

    //create a popover controller
    self.popoverController = [[[UIPopoverController alloc]
                               initWithContentViewController:popoverContent] autorelease];


    [popoverController presentPopoverFromRect:popoverButton.frame
                                            inView:self.view
                          permittedArrowDirections:UIPopoverArrowDirectionLeft
                                          animated:YES];


    //release the popover content
    [popoverView release];
    [popoverContent release];
}

Thank you

Was it helpful?

Solution

Your popoverButton is probably not a subview of self.view, so using its frame relative to that will result in an incorrect rectangle. Use popoverButton.bounds for the rectangle and popoverButton for the fromView parameter instead.

Note that the fromView parameter does not determine in which view the popover will be shown (it'll always be on top of everything), but rather relative to which view's coordinate system the rectangle should be interpreted.

OTHER TIPS

[popoverController presentPopoverFromRect:popRect inView:self.view  permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

try to change frame popRect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top