如何将一个Dialog View控制器作为子视图添加到UIView或副Versa? [英] How can I add a Dialog View Controller as a Subview to a UIView or Vice Versa?
问题描述
我有一个对话框视图。我有一个对话框视图。我有一个对话框视图。控制器和它的根只是显示一个类似于iphone音乐歌曲可滚动视图布局的字符串列表。我需要的是位于屏幕顶部的子视图和下面的可滚动DVC。我需要顶视图总是在视图中,而用户可以滚动根元素,因为顶视图将持有统计信息。
我已经尝试添加一个子视图,但它只是重叠的dvc下面,我没有能够找出一种方法添加dvc作为子视图到UIView。
任何帮助将非常感激。
是实现这是一个单一的根视图控制器,主机两个子视图控制器。一个子视图包含窗口顶部的统计信息。底部子视图包含保存对话框视图的导航控制器。
using System;
using System.Collections.Generic;
using System.Linq;
使用MonoTouch.Foundation;
使用MonoTouch.UIKit;
使用MonoTouch.Dialog;
using System.Drawing;
命名空间delete201205203
{
[注册(AppDelegate)]
public partial class AppDelegate:UIApplicationDelegate
{
UIWindow window;
MyUIViewController _mvc;
public override bool FinishedLaunching(UIApplication app,NSDictionary options)
{
window = new UIWindow(UIScreen.MainScreen.Bounds);
_mvc = new MyUIViewController();
window.RootViewController = _mvc;
window.MakeKeyAndVisible();
return true;
}
}
public class MyUIViewController:UIViewController
{
MyDialogViewController _dvc;
UINavigationController _nav;
StatisticsViewController _statistics;
public override void ViewDidLoad()
{
base.ViewDidLoad();
var root = new RootElement(Root){
new Section(Section){
new EntryElement(caption,placeholder,
new RootElement(Root 2){
new Section(Section){
new EntryElement(caption,placeholder,),
new StringElement (Back,()=> {
_nav.PopViewControllerAnimated(true);
})
}
}
}
}
_dvc = new MyDialogViewController(root);
_nav = new UINavigationController(_dvc);
_nav.SetNavigationBarHidden(true,false);
_nav.View.Frame = new RectangleF(0,70f,
this.View.Bounds.Width,
this.View.Bounds.Height -70f);
_statistics = new StatisticsViewController();
_statistics.View.Frame = new RectangleF(0,0,
this.View.Bounds.Width,
70f);
this.AddChildViewController(_nav);
this.View.AddSubview(_nav.View);
this.AddChildViewController(_statistics);
this.View.AddSubview(_statistics.View);
}
public override void ViewWillLayoutSubviews()
{
base.ViewWillLayoutSubviews();
_nav.View.Frame = new RectangleF(0,70f,
this.View.Bounds.Width,
this.View.Bounds.Height -70f);
_statistics.View.Frame = new RectangleF(0,0,
this.View.Bounds.Width,
70f);
}
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
}
public class StatisticsViewController:UIViewController
{
UILabel _label;
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.View.BackgroundColor = UIColor.White;
_label = new UILabel(new RectangleF(this.View.Bounds.Width * .5f - 50f,
this.View.Bounds.Height * .5f -10f,
100f,20f));
_label.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
_label.Text =statistics;
this.View.AddSubview(_label);
}
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
}
//这个重写是需要的,以确保流行视图动画
//在横向模式下正确工作
public class MyDialogViewController:DialogViewController
{
public MyDialogViewController(RootElement root):base(root){}
public override bool ShouldAutorotateToInterfaceOrientation(UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
}
}
I have looked around the web for some time looking for any resources on this topic and have come up with nothing that solves my dilemma.
I have a dialog view controller and its root is simply displaying a list of strings similar to how the iphone music song scrollable view is laid out. What I need is a subview located at the top of the screen and the scrollable DVC below it. I need to the top view to be always in view while the user can scroll through the root element because the top view will be holding statistics.
I have tried adding a subview but it simply overlaps the dvc below it, and I have not been able to figure out a way to add a dvc as a subview to a UIView.
Any help would be much appreciated.
What is needed to achieve this is a single root view controller that hosts two subview controllers. One subview contains the statistics at the top of the window. The bottom subview contains a navigation controller that holds the dialog view.
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.Dialog;
using System.Drawing;
namespace delete201205203
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
MyUIViewController _mvc;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
_mvc = new MyUIViewController ();
window.RootViewController = _mvc;
window.MakeKeyAndVisible ();
return true;
}
}
public class MyUIViewController : UIViewController
{
MyDialogViewController _dvc;
UINavigationController _nav;
StatisticsViewController _statistics;
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
var root = new RootElement ("Root") {
new Section ("Section") {
new EntryElement ("caption", "placeholder", ""),
new RootElement ("Root 2") {
new Section ("Section") {
new EntryElement ("caption", "placeholder", ""),
new StringElement ("Back", () => {
_nav.PopViewControllerAnimated (true);
})
}
}
}
};
_dvc = new MyDialogViewController (root);
_nav = new UINavigationController (_dvc);
_nav.SetNavigationBarHidden (true, false);
_nav.View.Frame = new RectangleF (0, 70f,
this.View.Bounds.Width,
this.View.Bounds.Height -70f);
_statistics = new StatisticsViewController ();
_statistics.View.Frame = new RectangleF (0, 0,
this.View.Bounds.Width,
70f);
this.AddChildViewController (_nav);
this.View.AddSubview (_nav.View);
this.AddChildViewController (_statistics);
this.View.AddSubview (_statistics.View);
}
public override void ViewWillLayoutSubviews ()
{
base.ViewWillLayoutSubviews ();
_nav.View.Frame = new RectangleF (0, 70f,
this.View.Bounds.Width,
this.View.Bounds.Height -70f);
_statistics.View.Frame = new RectangleF (0, 0,
this.View.Bounds.Width,
70f);
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
}
public class StatisticsViewController : UIViewController
{
UILabel _label;
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
this.View.BackgroundColor = UIColor.White;
_label = new UILabel (new RectangleF (this.View.Bounds.Width * .5f - 50f,
this.View.Bounds.Height * .5f -10f,
100f, 20f));
_label.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
_label.Text = "statistics";
this.View.AddSubview (_label);
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
}
// This overrde is needed to ensure the pop view animation
// works correctly in landscape mode
public class MyDialogViewController : DialogViewController
{
public MyDialogViewController (RootElement root) : base (root) {}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
return true;
}
}
}
这篇关于如何将一个Dialog View控制器作为子视图添加到UIView或副Versa?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!