zoukankan      html  css  js  c++  java
  • UISplitViewController-分割控件自定义分割宽度是无法实现的

    这篇文档主要说明,在分割控件的使用中,遇到的一些问题。

    分割控件中,苹果官方给的一个方法,来控制弹出页面的方法。

    self.contentSizeForViewInPopover = CGSizeMake(100.0, 600.0);

    根据帮助文档说明,改方法来控制弹出的分割控件的尺寸大小。

    但是,在实际应用中,却发先不起任何作用。纳闷啊。

    原来,压根就不起作用,调试了很久,找了很久。最后得出的结论是:分割控件的控制视图是无法自定义大小的。

    在苹果的方法中,虽然预留了这样的方法,但是实现不给力啊!设置无效啊!

    所以,想要自定义分割控件页面大小的美好愿望是不能够满足的!

    没兴趣知道原因的,就不用再往下看了!

    结果知道了,到底为什么呢?如果有兴趣,可以看一下,到底发生了什么!开始探究!

    仔细,查看这个方法的帮助文旦,发现这么一句话:

    可见,表述是说明,该属性是可以设置弹出视图的大小的。

    可是我进行设置:

    self.splitViewController.contentSizeForViewInPopover=CGSizeMake(100.0, 600.0);

    遗憾的是,并没有起任何作用。

    于是乎,我顺藤摸瓜,看contentSizeForViewInPopover方法能为我们带来什么惊喜

    contentSizeForViewInPopover

    The size of the view controller’s view while displayed in a popover.

    @property(nonatomic, readwrite) CGSize contentSizeForViewInPopover

    Discussion

    This property contains the desired size for the view controller when it is displayed in a popover. By default, the width is set to 320 points and the height is set to 1100 points. You can change these values as needed.

    The recommended width for popovers is 320 points. If needed, you can return a width value as large as 600 points, but doing so is not recommended.

    If the popover controller displaying the view controller sets its popoverContentSize property, the popover controller overrides the values set in the view controller’s contentSizeForViewInPopoverproperty.

    从这一段代码中,我们知道,默认的弹出视图大小为320*1100.

    并且推荐的是320的宽度,但是,可以设置成600,但是这是不推荐的。(可以没有说不允许啊)。

     

    并且可以设置这个属性,但是,都没有成功。

    但是 ,我有找到一个线索,UIPopoverController 的popoverContentSize属性能够控制弹出视图的大小,并且重写splitViewController.contentSizeForViewInPopover 属性的值,来改变大小。

    答案还没出现,还得继续找!

    如何设置 popoverContentSize 这个属性值呢?!

    想到了,<</span>UISplitViewControllerDelegate>委托的方法。

    // Called when a button should be added to a toolbar for a hidden view controller.

    // Implementing this method allows the hidden view controller to be presented via a swipe gesture if 'presentsWithGesture' is 'YES' (the default).

    - (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController*)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc;

    // Called when the view is shown again in the split view, invalidating the button and popover controller.

    - (void)splitViewController:(UISplitViewController *)svc willShowViewController:(UIViewController*)aViewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem;

    // Called when the view controller is shown in a popover so the delegate can take action like hiding other popovers.

    - (void)splitViewController:(UISplitViewController *)svc popoverController:(UIPopoverController *)pc willPresentViewController:(UIViewController *)aViewController;

    // Returns YES if a view controller should be hidden by the split view controller in a given orientation.

    // (This method is only called on the leftmost view controller and only discriminates portrait from landscape.)

    - (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientationNS_AVAILABLE_IOS(5_0);

    对这些委托方法,大概了解了一下后,于是我重写了全部方法,并设置了popoverContentSize属性值。

    #pragma mark - Split view

    // 苹果官方建议,当控制视图隐藏的时候,应该将一个按钮添加到toolbar上,这样可以控制“控制视图”的显示和隐藏

    - (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController*)popoverController

    {

        barButtonItem.title = NSLocalizedString(@"显示", @"显示");

        [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];

        self.masterPopoverController = popoverController;

        popoverController.popoverContentSize=CGSizeMake(500.0, 600.0);

    }

    // 苹果官方建议,当控制视图隐藏的时候,应该将一个按钮添加到toolbar上,这样可以控制“控制视图”的显示和隐藏

    // 当“控制视图”在分割视图上显示时,将调用该方法。

    // Called when the view is shown again in the split view, invalidating the button and popover controller.

    - (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem

    {

        _masterPopoverController.popoverContentSize=CGSizeMake(500.0, 600.0);

    }

    // 根据iPad方向,来控制,是否隐藏“控制视图”,默认的是允许。即竖着(肖像)模式时,隐藏;横着(风景)模式时,显示

    - (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInterfaceOrientation)orientation{

        return YES;

    }

    遗憾的是,根本就没有没有实现重定义分割视图的大小!

    研究到此终止吧。不要在纠结改变UISplitViewController宽度的的事情上了,还有很多事情等着我们去做!

    但是,总要有个结论吧。

    既然,官方给出的控件不行,那只有自造吧。在View中放入两个View做协调是个不错的办法啊。也只有这样了,自己动手造车!

    也在网上,看到一个牛人写的自定义分割视图,原理也是自己重绘的界面!(看来,也许真的不支持)。又找到一个苹果的Bug啊。

    改休息了。晚安!(死了心,也就睡的好了,纠结了2天的无言结局)!

  • 相关阅读:
    Linux(Centos)安装图形化界面步骤
    Delphi 取得桌面文件夹的路径和取得我的文档的路径
    Nginx [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
    待查消息
    WM_SETFOCUS和WM_KILLFOCUS、WM_GETDLGCODE、CM_ENTER...
    WM_SIZE
    MongoDB 开启与关闭
    log4j 日志文件路径
    wamp中修改配置支持多站点
    java 下载示例
  • 原文地址:https://www.cnblogs.com/huangh/p/4110507.html
Copyright © 2011-2022 走看看