Change preferred content size of PopOverViewController on fly

爱⌒轻易说出口 提交于 2019-12-12 05:28:38

问题


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:


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



来源:https://stackoverflow.com/questions/28112617/change-preferred-content-size-of-popoverviewcontroller-on-fly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!