problem in setting PopoverContentSize

2019-02-19 02:31发布

I am not able to set the contentsize with size(650,400).But even i create popoverController with same width & height it is getting created.

No idea what is worry ? On tapping Enter it shows as below

enter image description here

- (IBAction)setButtonTapped:(id)sender
{
     popover *mpopover      =   [[popover alloc] init];

    UINavigationController  *NavController      =   [[UINavigationController alloc] initWithRootViewController:mpopover];

    //NavController.navigationBar.backgroundColor = [UIColor darkGrayColor];
    mPickerPopover  = [[[UIPopoverController alloc] initWithContentViewController:NavController] retain];

    CGSize popoversize      =   CGSizeMake(400, 90);

    [mpopover setparent:mPickerPopover];

    [mpopover setToolBarFrame:popoversize];

    mPickerPopover.popoverContentSize   = popoversize;

    [mPickerPopover presentPopoverFromRect:CGRectMake([sender frame].origin.x, [sender frame].origin.y, 20, 20) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

    [mpopover release];
}

On tapping show button looks like this enter image description here

 -(void)buttonView:(id)sender
 {

  CGSize popoversize        =   CGSizeMake(650, 320);

  [parent setPopoverContentSize:popoversize animated:YES];


  [toolbar setFrame:CGRectMake(0, popoversize.height- 90, popoversize.width, 60)];

  CATransition *transition = [CATransition animation];
  transition.type = kCATransitionPush;
  transition.duration = 1.0f;
  transition.timingFunction = UIViewAnimationCurveEaseInOut;
  [self.view.layer addAnimation:transition forKey:@"transitionViewAnimation"];
  }

5条回答
再贱就再见
2楼-- · 2019-02-19 02:51

I noticed you have a UIViewController called popover which should be shown inside the popoever that you have referenced as mpopover navigate to that class and in the ViewDidLoad Method of the ViewController cycle make sure to add the following code

self.contentSizeForViewInPopover = CGSizeMake(400, 90); // or Any size you like

...&...

查看更多
啃猪蹄的小仙女
3楼-- · 2019-02-19 02:54

Consider using:

-(BOOL)splitViewController:(UISplitViewController *)svcontroller shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation 
{
    return NO;
}

This will present the popover in portrait and landscape orientations.

查看更多
甜甜的少女心
4楼-- · 2019-02-19 02:58

I was having a similar problem in that I was unable to change the size of a popover controller during device rotation. I found the information that lead to my solution in a answer to a similar question.

Because I was presenting the popover from a Bar button, UIKit was "trying" to help by adjusting the size of the popover during rotation (because the position of the button might be different after a change to a different device orientation). Even though I knew exactly what size I wanted the popover to be in every case, it wasn't respecting my calls to setPopoverContentSize. My solution was to dismiss the popover in willAnimateRotationToInterfaceOrientation, then re-present the same popover in didRotateFromInterfaceOrientation after setting appropriate values for both contentSizeForViewInPopover and popoverContentSize. IHTH

查看更多
爷、活的狠高调
5楼-- · 2019-02-19 03:05

From Apple's documentation:

"the width value you specify must be at least 320 points and no more than 600 points."

Maybe trying to set the width to 650 is the problem.

查看更多
干净又极端
6楼-- · 2019-02-19 03:07

It's not very clear what you are asking but with popovers you need to make sure you set the popoverContentSize on the content view controller before displaying the popover. Usually I do this in viewDidLoad method of my view controllers that will be used in popovers.

查看更多
登录 后发表回答