1

我在 MvvmCross 项目中将 UIScrollable 控件添加到屏幕时遇到问题。我在视图的子视图中添加了一个 scrollView 控件,此后,我感谢任何帮助。这是视图确实加载的代码:

 public override void ViewDidLoad()
    {
        View = new UniversalView();

        base.ViewDidLoad();



        this.scrollView = new UIScrollView(new RectangleF(0, 0, this.View.Frame.Width, this.View.Frame.Height - this.NavigationController.NavigationBar.Frame.Height));
        this.View.AddSubview(scrollView);



        var lastName = new UITextField(new RectangleF(0f, 0f, 320f, 40f));
        lastName.Placeholder = "Last Name";
        this.View.AddSubview(lastName);
        var firstName = new UITextField(new RectangleF(0f, 50f, 320f, 40f));
        firstName.Placeholder = "First Name";
        this.View.AddSubview(firstName);
        var middleInitial = new UITextField(new RectangleF(0f, 100f, 320f, 40f));
        middleInitial.Placeholder = "Middle Initial";
        this.View.AddSubview(middleInitial);
        var phoneNumber = new UITextField(new RectangleF(0f, 150f, 320f, 40f));
        phoneNumber.Placeholder = "Phone Number";
        this.View.AddSubview(middleInitial);
        var streetAddress = new UITextField(new RectangleF(0f, 200f, 320f, 40f));
        streetAddress.Placeholder = "Street Address";
        this.View.AddSubview(streetAddress);
        var city = new UITextField(new RectangleF(0f, 250f, 320f, 40f));
        city.Placeholder = "City";
        this.View.AddSubview(city);
        var state = new UITextField(new RectangleF(0f, 200f, 320f, 40f));
        state.Placeholder = "State";
        this.View.AddSubview(state);
        var zip = new UITextField(new RectangleF(0f, 250f, 320f, 40f));
        zip.Placeholder = "Zip Code";
        this.View.AddSubview(zip);
        var date = new UITextField(new RectangleF(0f, 200f, 320f, 40f));
        date.Placeholder = "Date of Appointment";
        this.View.AddSubview(date);
        var agentID = new UITextField(new RectangleF(0f, 250f, 320f, 40f));
        agentID.Placeholder = "Agent ID";
        this.View.AddSubview(agentID);

        var set = this.CreateBindingSet<AddScope, AddScopeViewModel>();
        set.Bind(lastName).To(vm => vm.BeneficiaryLastName);
        set.Bind(firstName).To(vm => vm.BeneficiaryFirstName);
        set.Bind(middleInitial).To(vm => vm.BeneficiaryMiddleInitial);
        set.Bind(phoneNumber).To(vm => vm.BeneficiaryPhone);
        set.Bind(streetAddress).To(vm => vm.BeneficiaryStreetAddress);
        set.Bind(city).To(vm => vm.BeneficiaryCity);
        set.Bind(state).To(vm => vm.BeneficiaryState);
        set.Bind(zip).To(vm => vm.BeneficiaryZip);
        set.Bind(date).To(vm => vm.DateOfAppointment);
        set.Bind(agentID).To(vm => vm.AgentID);
        set.Apply();

    }
4

1 回答 1

1

它认为该示例代码的主要问题是您没有将 child UIViews 添加到UIScrollView

一个快速的解决方法可能是使用滚动视图作为你的主视图:

public override void ViewDidLoad()
{
    View = 
            new UIScrollView(new RectangleF(0, 0, this.View.Frame.Width,
                                            this.View.Frame.Height))
                {
                    ContentSize = new SizeF(320, 800),
                    BackgroundColor = UIColor.Red
                };

    base.ViewDidLoad();

    var lastName = new UITextField(new RectangleF(0f, 0f, 320f, 40f));
    lastName.Placeholder = "Last Name";
    this.View.AddSubview(lastName);
    var firstName = new UITextField(new RectangleF(0f, 50f, 320f, 40f));
    firstName.Placeholder = "First Name";
    this.View.AddSubview(firstName);
    var middleInitial = new UITextField(new RectangleF(0f, 100f, 320f, 40f));
    middleInitial.Placeholder = "Middle Initial";
    this.View.AddSubview(middleInitial);
    var phoneNumber = new UITextField(new RectangleF(0f, 150f, 320f, 40f));
    phoneNumber.Placeholder = "Phone Number";
    this.View.AddSubview(middleInitial);
    var streetAddress = new UITextField(new RectangleF(0f, 200f, 320f, 40f));
    streetAddress.Placeholder = "Street Address";
    this.View.AddSubview(streetAddress);
    var city = new UITextField(new RectangleF(0f, 250f, 320f, 40f));
    city.Placeholder = "City";
    this.View.AddSubview(city);
    var state = new UITextField(new RectangleF(0f, 200f, 320f, 40f));
    state.Placeholder = "State";
    this.View.AddSubview(state);
    var zip = new UITextField(new RectangleF(0f, 250f, 320f, 40f));
    zip.Placeholder = "Zip Code";
    this.View.AddSubview(zip);
    var date = new UITextField(new RectangleF(0f, 200f, 320f, 40f));
    date.Placeholder = "Date of Appointment";
    this.View.AddSubview(date);
    var agentID = new UITextField(new RectangleF(0f, 250f, 320f, 40f));
    agentID.Placeholder = "Agent ID";
    this.View.AddSubview(agentID);

    var set = this.CreateBindingSet<AddScope, AddScopeViewModel>();
    set.Bind(lastName).To(vm => vm.BeneficiaryLastName);
    set.Bind(firstName).To(vm => vm.BeneficiaryFirstName);
    set.Bind(middleInitial).To(vm => vm.BeneficiaryMiddleInitial);
    set.Bind(phoneNumber).To(vm => vm.BeneficiaryPhone);
    set.Bind(streetAddress).To(vm => vm.BeneficiaryStreetAddress);
    set.Bind(city).To(vm => vm.BeneficiaryCity);
    set.Bind(state).To(vm => vm.BeneficiaryState);
    set.Bind(zip).To(vm => vm.BeneficiaryZip);
    set.Bind(date).To(vm => vm.DateOfAppointment);
    set.Bind(agentID).To(vm => vm.AgentID);
    set.Apply();
}
于 2013-06-11T13:18:39.580 回答