【问题标题】:UIPopoverController w/MonoTouch.Dialog results in unwanted resizing of popoverUIPopoverController w/MonoTouch.Dialog 会导致不需要的弹出框大小调整
【发布时间】:2012-02-07 17:11:21
【问题描述】:

我在 UIPopoverController 中使用 MonoTouch.Dialog 为我们的 iPad 用户提供一系列可使用的设置。在我的应用程序中,我正在使用这个 CalendarView (http://escoz.com/blog/monotouch-calendar-control-is-here/),因此用户可以为应用程序设置日期(这些设置用于在谷歌地图)。

无论如何,我遇到了一些关于 UIPopoverController 的大小调整问题...无论我如何设置内容大小,一旦我深入点击 .Dialog 的树,UIPopoverController 就会自行调整大小,这会导致在所述日历视图上出现不希望的大小.

随附的是我所看到的示例。您会注意到,我的内容大小为 450x420。单击任何选项后,弹出框会自行调整大小。我希望这个弹出框始终保持相同的大小。

我在这里遗漏了一些明显的东西吗?任何帮助将不胜感激。

从 myPopOverView.cs 声明并启动弹出框:

UIPopoverController myPopOver = new UIPopoverController(new myPopOverView()); 

btnSearch.TouchUpInside += (sender, e) => {
   myPopOver.PopoverContentSize = new SizeF(450f, 420f);
   myPopOver.PresentFromRect (btnPopOver.Frame, this.View, UIPopoverArrowDirection.Down, true);
}   

来自 myPopOverView.cs:

public override void ViewDidLoad ()
   {
  base.ViewDidLoad ();

  var root = CreateRoot ();

  var dv = new DialogViewController (root, true);
  this.PushViewController (dv, true);
}

RootElement CreateRoot ()
    {

        return new RootElement ("Find Stuff") {
                new Section (){
                    new RootElement ("States", new RadioGroup (0)){
                        new Section (){
                            new RadioElement ("New York"),
                            new RadioElement ("California"),
                            new RadioElement ("Texas"), 
                        }
                    }  , 
                }  ,
                new Section (){
                    new RootElement ("Places", new RadioGroup (0)){
                        new Section (){
                            new RadioElement ("New York City"),
                            new RadioElement ("San Francisco"),
                            new RadioElement ("Dallas"), 
                        }
                    }  , 
                }  ,
                new Section (){
                    new RootElement ("Products") {
                            from sh in "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 
                                select new Section (sh + " - Section") {
                                   from filler in "12345" 
                                    select (Element) new CheckboxElement (sh + " - " + filler, true, "kb")
                            }

                    }  , 
                }  

        }  ;        
    }

【问题讨论】:

    标签: xamarin.ios uipopovercontroller monotouch.dialog


    【解决方案1】:

    每次 TopViewController 改变 UIPopoverController 都会尝试自动协商它的 ContentSize。

    您应该通过覆盖 WillShowViewController 方法并在那里设置 SizeF 来为每个 UIViewController 设置 ContentSizeForViewInPopover。

    【讨论】:

    • 感谢 Anuj 朝着正确的方向前进。我最终为我的 UINavigationController 设置了一个委托,该委托具有 WillShowViewController 的覆盖......就像一个冠军! (我什至可以使用视图控制器上的开关来设置每个视图控制器的高度)谢谢!!
    • 太棒了,很高兴有帮助。这实际上听起来像是 .NET 事件化代替委托方法覆盖的一个很好的候选者。如果达到了预期的行为,请随意标记为答案:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-21
    • 1970-01-01
    • 2015-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多