Change preferred content size of PopOverViewContro

2019-09-07 00:31发布

I am trying to change the preferred content size of a UIPopOverController from inside the childViewController.

Firstly I present PopOverViewController this way

 DateViewController *dateView = [[DatePickerViewController alloc] initWithNibName:@"DateViewController" bundle:nil];

        UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:dateView];


        m_tableCell = (NotesCell *)[m_tableView cellForRowAtIndexPath:indexPath];


            popViewController = [[UIPopoverController alloc] initWithContentViewController:navController];
            popViewController.backgroundColor = [[AppManager instance].themeManager navigationBarColor];
            popViewController.delegate = self;


                //the rectangle here is the frame of the object that presents the popover,
                //in this case, the UIButton…


                CGRect popRect = CGRectMake(m_tableCell.customView.frame.origin.x,
                                            m_tableCell.customView.frame.origin.y,
                                            m_tableCell.customView.frame.size.width,
                                            m_tableCell.customView.frame.size.height);
                                [popViewController presentPopoverFromRect:popRect
                                                   inView:m_tableCell
                                 permittedArrowDirections:UIPopoverArrowDirectionRight
                                                 animated:YES];

So inside my childViewController i.e (DateViewController), I have button which when toggled will call a function

    - (void)toggleButton
    {
       if(small)
       {
               self.presentingViewController.presentedViewController.preferredContentSize = CGSizeMake(320,485);
       }
       else
       {
             self.presentingViewController.presentedViewController.preferredContentSize = CGSizeMake(320,320);
       }
}

This is working fine, but as we know that UIPopOverViewController has arrow, so when I resize the popOverView, the arrow also animates up and down, which I dont want. I cannot show this in image, so please excuse me for that.

Need help

Ranjit.

1条回答
我只想做你的唯一
2楼-- · 2019-09-07 01:24

First of all the code you posted won't work, because in else statement you assign CGSizeMake giving only one value while constructing it.

Secondly you can define in which directions you allow for that arrow by specifying popoverArrowDirection property

查看更多
登录 后发表回答