c# iOS scrollView 不会滚动

c# iOS scrollView will not scroll

我有一个创建帐户视图,用户可以使用它在系统中创建帐户。我已经正确布置了视图,但无法向下滚动。我在网上到处寻找建议,最普遍的是内容小于或与 scrollView 大小相同。我添加了代码以确保不会发生这种情况,但仍然无法滚动。

我的代码:

public partial class createAccount : UIViewController
{
    public User MyUser;
    UIScrollView scrollView = new UIScrollView();
    public DataInterfaceWeb.DataInterface myService = new DataInterfaceWeb.DataInterface();
    List<string> Questions = new List<string>();
    public createAccount (IntPtr handle) : base (handle)
    {
    }

    public override void ViewDidLoad()
    {

        base.ViewDidLoad();
        var height = this.NavigationController.NavigationBar.Bounds.Height;
        View.BackgroundColor = UIKit.UIColor.FromRGB(255, 215, 0);
        nfloat bannerHeight = banner.Frame.Height;
        nfloat lblTitleHeight = lblTitle.Frame.Height;

        UILabel lblUsername = new UILabel();
        UITextField txtUsername = new UITextField();
        txtUsername.BackgroundColor = UIColor.LightGray;
        lblUsername.Text = "Enter Username: ";
        txtUsername.Placeholder = "Enter Username";

        UILabel lblPassword = new UILabel();
        lblPassword.Text = "Enter Password: ";

        UITextField txtPassword = new UITextField();
        txtPassword.Placeholder = "Enter Password";
        txtPassword.BackgroundColor = UIColor.LightGray;

        UILabel lblConfirmPassword = new UILabel();
        lblConfirmPassword.Text = "Confirm Password: ";
        UITextField txtConfirmPassword = new UITextField();
        txtConfirmPassword.Placeholder = "Confirm Password";
        txtConfirmPassword.BackgroundColor = UIColor.LightGray;

        UILabel lblEmailAddress = new UILabel();
        lblEmailAddress.Text = "Enter Email Address: ";
        UITextField txtEmailAddress = new UITextField();
        txtEmailAddress.Placeholder = "Enter Email Address";
        txtEmailAddress.BackgroundColor = UIColor.LightGray;

        UILabel lblConfirmEmailAddress = new UILabel();
        lblConfirmEmailAddress.Text = "Confirm Email Address: ";
        UITextField txtConfirmEmailAddress = new UITextField();
        txtConfirmEmailAddress.Placeholder = "Confirm Email Address";
        txtConfirmEmailAddress.BackgroundColor = UIColor.LightGray;

        UILabel lblSelectQuestion = new UILabel();
        lblSelectQuestion.TextAlignment = UITextAlignment.Center;
        lblSelectQuestion.Text = "Select Challenge Question";

        UITextField challengeQuestion = new UITextField();
        challengeQuestion.TextColor = UIKit.UIColor.Blue;
        challengeQuestion.TextAlignment = UITextAlignment.Center;
        challengeQuestion.Text = "Select Challenge Question";

        UILabel lblAnswer = new UILabel();
        lblAnswer.TextAlignment = UITextAlignment.Center;
        lblAnswer.BackgroundColor = UIColor.LightGray ;
        lblAnswer.Text = "Challenge Question Answer";

        UITextField txtChallengeAnswer = new UITextField();
        txtChallengeAnswer.Placeholder = "Enter Challenge Question Answer";
        txtChallengeAnswer.TextAlignment = UITextAlignment.Center;

        UILabel lblFirstName = new UILabel();
        lblFirstName.Text = "First Name: ";

        UITextField txtFirstName = new UITextField();
        txtFirstName.Placeholder = "Enter First Name";
        txtFirstName.BackgroundColor = UIColor.LightGray;

        UILabel lblMI = new UILabel();
        lblMI.Text = "Middle Initial: ";

        UITextField txtMI = new UITextField();
        txtMI.Placeholder = "MI";
        txtMI.BackgroundColor = UIColor.LightGray;

        UILabel lblLastName = new UILabel();
        lblLastName.Text = "Last Name: ";

        UITextField txtLastName = new UITextField();
        txtLastName.Placeholder = "Enter Last Name";
        txtLastName.BackgroundColor = UIColor.LightGray;

        UILabel lblSuffix = new UILabel();
        lblSuffix.Text = "Suffix: ";

        UITextField txtSuffix = new UITextField();
        txtSuffix.Text = "None";
        txtSuffix.TextColor = UIKit.UIColor.Blue;

        UILabel lblAddress = new UILabel();
        lblAddress.Text = "Address: ";

        UITextField txtAddress = new UITextField();
        txtAddress.Placeholder = "Enter Address";
        txtAddress.BackgroundColor = UIColor.LightGray;

        UILabel lblCity = new UILabel();
        lblCity.Text = "City: ";

        UITextField txtCity = new UITextField();
        txtCity.Placeholder = "Enter City";
        txtCity.BackgroundColor = UIColor.LightGray;

        UILabel lblState = new UILabel();
        lblState.Text = "State: ";

        UITextField txtState = new UITextField();
        txtState.TextColor = UIKit.UIColor.Blue;
        txtState.Text = "Select State";

        UILabel lblZip = new UILabel();
        lblZip.Text = "Zip: ";

        UITextField txtZip = new UITextField();
        txtZip.Placeholder = "Enter Zip";
        txtZip.BackgroundColor = UIColor.LightGray;

        UILabel lblPhone = new UILabel();
        lblPhone.Text = "Contact Phone:";

        UITextField txtPhone = new UITextField();
        txtPhone.Placeholder = "Enter Phone Number";
        txtPhone.BackgroundColor = UIColor.LightGray;

        UILabel lblSelectPhoneType = new UILabel();
        lblSelectPhoneType.Text = "Select Phone Type";

        UITextField txtSelectPhoneType = new UITextField();
        txtSelectPhoneType.Text = "Select Phone Type";
        txtSelectPhoneType.TextColor = UIKit.UIColor.Blue;

        UILabel lblMessage = new UILabel();
        lblMessage.Text = "Select Company (if applicable) and department you are registering for.";
        lblMessage.TextColor = UIKit.UIColor.Blue;

        lblMessage.LineBreakMode = UILineBreakMode.WordWrap;
        // lblMessage.NumberOfLines = 0;

        UILabel lblSelectConference = new UILabel();
        lblSelectConference.Text = "Select Company (if applicable)";
        lblSelectConference.TextAlignment = UITextAlignment.Center;


        // scrollView.ContentSize = CGSize(;
        scrollView.Add(lblUsername);
        scrollView.Add(txtUsername);

        scrollView.Add(lblPassword);
        scrollView.Add(txtPassword);
        scrollView.Add(lblConfirmPassword);
        scrollView.Add(txtConfirmPassword);
        scrollView.Add(lblEmailAddress);
        scrollView.Add(txtEmailAddress);
        scrollView.Add(lblConfirmEmailAddress);
        scrollView.Add(txtConfirmEmailAddress);
        scrollView.Add(lblSelectQuestion);
        scrollView.Add(challengeQuestion);
        scrollView.Add(lblAnswer);
        scrollView.Add(txtChallengeAnswer);

        scrollView.Add(lblFirstName);
        scrollView.Add(txtFirstName);
        scrollView.Add(lblMI);
        scrollView.Add(txtMI);
        scrollView.Add(lblLastName);
        scrollView.Add(txtLastName);
        scrollView.Add(lblSuffix);
        scrollView.Add(txtSuffix);
        scrollView.Add(lblAddress);
        scrollView.Add(txtAddress);
        scrollView.Add(lblCity);
        scrollView.Add(txtCity);
        scrollView.Add(lblState);
        scrollView.Add(txtState);
        scrollView.Add(lblZip);
        scrollView.Add(txtZip);
        scrollView.Add(lblPhone);
        scrollView.Add(txtPhone);
        scrollView.Add(lblSelectPhoneType);
        scrollView.Add(txtSelectPhoneType);
        scrollView.Add(lblMessage);
        scrollView.Add(lblSelectConference);
        

        viewCreateAccount.Add(scrollView);

        scrollView.BackgroundColor = UIKit.UIColor.White;
        viewCreateAccount.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
        viewCreateAccount.AddConstraints
        (
            banner.AtTopOf(View, height),
            banner.AtRightOf(View, 0),
            banner.AtLeftOf(View, 0),

            lblTitle.Below(banner, 0),
            lblTitle.WithSameWidth(banner),

            scrollView.Below(lblTitle,0),
            scrollView.AtBottomOf(View,10),
            scrollView.AtLeftOf(View,10),
            scrollView.AtRightOf(View,10)
        );

        scrollView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
        scrollView.AddConstraints(
            lblUsername.AtTopOf(scrollView, 0),
            lblUsername.AtLeftOf(scrollView, 0),

            // txtUsername.Below(lblUsername, 0).Plus(5), // add below margin
            txtUsername.ToRightOf(lblUsername, 2),
            txtUsername.Width().EqualTo(250.0f),

            lblPassword.Below(lblUsername, 5),
            txtPassword.Below(lblUsername, 0).Plus(5), // add below margin
            txtPassword.ToRightOf(lblPassword, 2),
            txtPassword.Width().EqualTo(250.0f),

            lblConfirmPassword.Below(lblPassword, 5),
            txtConfirmPassword.Below(lblPassword, 0).Plus(5), // add below margin
            txtConfirmPassword.ToRightOf(lblConfirmPassword, 2),
            txtConfirmPassword.Width().EqualTo(250.0f),

            lblEmailAddress.Below(lblConfirmPassword, 5),
            txtEmailAddress.Below(lblConfirmPassword, 0).Plus(5), // add below margin
            txtEmailAddress.ToRightOf(lblEmailAddress, 2),
            txtEmailAddress.Width().EqualTo(250.0f),

            lblConfirmEmailAddress.Below(lblEmailAddress, 5),
            txtConfirmEmailAddress.Below(lblEmailAddress, 0).Plus(5), // add below margin
            txtConfirmEmailAddress.ToRightOf(lblConfirmEmailAddress, 2),
            txtConfirmEmailAddress.Width().EqualTo(250.0f),

            lblSelectQuestion.Below(lblConfirmEmailAddress).Plus(10),
            lblSelectQuestion.WithSameWidth(scrollView),

            challengeQuestion.WithSameWidth(scrollView),
            challengeQuestion.Below(lblSelectQuestion, 5).Plus(5),

            lblAnswer.Below(challengeQuestion, 5).Plus(5),
            lblAnswer.WithSameWidth(scrollView),

            txtChallengeAnswer.Below(lblAnswer).Plus(5),
            txtChallengeAnswer.WithSameWidth(scrollView),

            lblFirstName.Below(txtChallengeAnswer, 5),
            txtFirstName.Below(txtChallengeAnswer, 0).Plus(5), // add below margin
            txtFirstName.ToRightOf(lblFirstName, 2),
            txtFirstName.Width().EqualTo(250.0f),

            lblMI.Below(lblFirstName, 5),
            txtMI.Below(lblFirstName, 0).Plus(5), // add below margin
            txtMI.ToRightOf(lblMI, 2),
            txtMI.Width().EqualTo(50.0f),

            lblLastName.Below(lblMI, 5),
            txtLastName.Below(lblMI, 0).Plus(5), // add below margin
            txtLastName.ToRightOf(lblLastName, 2),
            txtLastName.Width().EqualTo(250.0f),

            lblSuffix.Below(lblLastName, 5),
            txtSuffix.Below(lblLastName, 0).Plus(5), // add below margin
            txtSuffix.ToRightOf(lblSuffix, 2),
            txtSuffix.Width().EqualTo(50.0f),

            lblAddress.Below(lblSuffix, 5),
            txtAddress.Below(lblSuffix, 0).Plus(5), // add below margin
            txtAddress.ToRightOf(lblAddress, 2),
            txtAddress.Width().EqualTo(250.0f),

            lblCity.Below(lblAddress, 5),
            txtCity.Below(lblAddress, 0).Plus(5), // add below margin
            txtCity.ToRightOf(lblCity, 2),
            txtCity.Width().EqualTo(250.0f),

            lblState.Below(lblCity, 5),
            txtState.Below(lblCity, 0).Plus(5), // add below margin
            txtState.ToRightOf(lblState, 2),
            txtState.Width().EqualTo(250.0f),

            lblZip.Below(lblState, 5),
            txtZip.Below(lblState, 0).Plus(5), // add below margin
            txtZip.ToRightOf(lblZip, 2),
            txtZip.Width().EqualTo(250.0f),

            lblPhone.Below(lblZip, 5),
            txtPhone.Below(lblZip, 0).Plus(5), // add below margin
            txtPhone.ToRightOf(lblPhone, 2),
            txtPhone.Width().EqualTo(200.0f),

            lblSelectPhoneType.Below(lblPhone, 5).Plus(5),
            lblSelectPhoneType.WithSameWidth(scrollView),

            txtSelectPhoneType.WithSameWidth(scrollView),
            txtSelectPhoneType.Below(lblSelectPhoneType, 5).Plus(5),

            //lblMessage.WithSameWidth(scrollView),
            lblMessage.Below(txtSelectPhoneType, 10).Plus(5),
            lblMessage.Width().EqualTo(350.0f),

            lblSelectConference.Below(lblMessage, 5).Plus(5),
            lblSelectConference.WithSameWidth(scrollView)

      );
        DataSet MyQuestionsDataset = myService.GetQuestions(myusername, mypassword, "REGISTRATION", "EN");
        Questions.Add("Select Challenge Question");
        foreach (DataRow MyDataRow in MyQuestionsDataset.Tables[0].Rows)
        {
            Questions.Add(MyDataRow["QUESTION"].ToString());

        };


        ConfigureChallengePicker(challengeQuestion, Questions);

        // Ensure content area is larger than scroll view
        var frame = scrollView.Frame;
        frame.Height += 250;
        scrollView.ContentSize = frame.Size;
        scrollView.ScrollEnabled = true;
    }

    void ConfigureChallengePicker(UITextField pickerTextField, List<string> theData)
    {
        PickerViewModel MyModel = new PickerViewModel();
        MyModel._pickerSource = theData;
        var picker = new UIPickerView
        {
            Model = MyModel,
            ShowSelectionIndicator = true
        };
        var screenWidth = UIScreen.MainScreen.Bounds.Width;
        var pickerToolBar = new UIToolbar(new RectangleF(0, 0, (float)screenWidth, 44)) { BarStyle = UIBarStyle.Default, Translucent = true };
        var flexibleSpaceButton = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
        var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, e) => pickerTextField.ResignFirstResponder());
        doneButton.Clicked += (object sender, EventArgs e) =>
        {
            pickerTextField.Text = MyModel.SelectedItem;
        };
        pickerToolBar.SetItems(new[] { flexibleSpaceButton, doneButton }, false);

        pickerTextField.InputView = picker;
        pickerTextField.InputAccessoryView = pickerToolBar;
    }
}

我错过了什么?

成功了,显然我没有为滚动视图内容大小设置足够大的框架。无论如何,我将代码更改为:

public partial class createAccount : UIViewController
{
    public User MyUser;
    UIScrollView scrollView;

    public DataInterfaceWeb.DataInterface myService = new DataInterfaceWeb.DataInterface();
    List<string> Questions = new List<string>();

    float h = 50.0f;
    float w = 50.0f;
    float padding = 10.0f;
    int n = 25;


    public createAccount (IntPtr handle) : base (handle)
    {
    }

    public override void ViewDidLoad()
    {

        scrollView = new UIScrollView
        {
            Frame = new CGRect(0, 0, viewCreateAccount.Frame.Width, h + 2 * padding),
            ContentSize = new SizeF((w + padding), (h + padding) * n),
            BackgroundColor = UIColor.DarkGray,
            AutoresizingMask = UIViewAutoresizing.FlexibleWidth
        };

        base.ViewDidLoad();
        var height = this.NavigationController.NavigationBar.Bounds.Height;
        View.BackgroundColor = UIKit.UIColor.FromRGB(255, 215, 0);
        nfloat bannerHeight = banner.Frame.Height;
        nfloat lblTitleHeight = lblTitle.Frame.Height;

        UILabel lblUsername = new UILabel();
        UITextField txtUsername = new UITextField();
        txtUsername.BackgroundColor = UIColor.LightGray;
        lblUsername.Text = "Enter Username: ";
        txtUsername.Placeholder = "Enter Username";

        UILabel lblPassword = new UILabel();
        lblPassword.Text = "Enter Password: ";

        UITextField txtPassword = new UITextField();
        txtPassword.Placeholder = "Enter Password";
        txtPassword.BackgroundColor = UIColor.LightGray;

        UILabel lblConfirmPassword = new UILabel();
        lblConfirmPassword.Text = "Confirm Password: ";
        UITextField txtConfirmPassword = new UITextField();
        txtConfirmPassword.Placeholder = "Confirm Password";
        txtConfirmPassword.BackgroundColor = UIColor.LightGray;

        UILabel lblEmailAddress = new UILabel();
        lblEmailAddress.Text = "Enter Email Address: ";
        UITextField txtEmailAddress = new UITextField();
        txtEmailAddress.Placeholder = "Enter Email Address";
        txtEmailAddress.BackgroundColor = UIColor.LightGray;

        UILabel lblConfirmEmailAddress = new UILabel();
        lblConfirmEmailAddress.Text = "Confirm Email Address: ";
        UITextField txtConfirmEmailAddress = new UITextField();
        txtConfirmEmailAddress.Placeholder = "Confirm Email Address";
        txtConfirmEmailAddress.BackgroundColor = UIColor.LightGray;

        UILabel lblSelectQuestion = new UILabel();
        lblSelectQuestion.TextAlignment = UITextAlignment.Center;
        lblSelectQuestion.Text = "Select Challenge Question";

        UITextField challengeQuestion = new UITextField();
        challengeQuestion.TextColor = UIKit.UIColor.Blue;
        challengeQuestion.TextAlignment = UITextAlignment.Center;
        challengeQuestion.Text = "Select Challenge Question";

        UILabel lblAnswer = new UILabel();
        lblAnswer.TextAlignment = UITextAlignment.Center;
        lblAnswer.BackgroundColor = UIColor.LightGray ;
        lblAnswer.Text = "Challenge Question Answer";

        UITextField txtChallengeAnswer = new UITextField();
        txtChallengeAnswer.Placeholder = "Enter Challenge Question Answer";
        txtChallengeAnswer.TextAlignment = UITextAlignment.Center;

        UILabel lblFirstName = new UILabel();
        lblFirstName.Text = "First Name: ";

        UITextField txtFirstName = new UITextField();
        txtFirstName.Placeholder = "Enter First Name";
        txtFirstName.BackgroundColor = UIColor.LightGray;

        UILabel lblMI = new UILabel();
        lblMI.Text = "Middle Initial: ";

        UITextField txtMI = new UITextField();
        txtMI.Placeholder = "MI";
        txtMI.BackgroundColor = UIColor.LightGray;

        UILabel lblLastName = new UILabel();
        lblLastName.Text = "Last Name: ";

        UITextField txtLastName = new UITextField();
        txtLastName.Placeholder = "Enter Last Name";
        txtLastName.BackgroundColor = UIColor.LightGray;

        UILabel lblSuffix = new UILabel();
        lblSuffix.Text = "Suffix: ";

        UITextField txtSuffix = new UITextField();
        txtSuffix.Text = "None";
        txtSuffix.TextColor = UIKit.UIColor.Blue;

        UILabel lblAddress = new UILabel();
        lblAddress.Text = "Address: ";

        UITextField txtAddress = new UITextField();
        txtAddress.Placeholder = "Enter Address";
        txtAddress.BackgroundColor = UIColor.LightGray;

        UILabel lblCity = new UILabel();
        lblCity.Text = "City: ";

        UITextField txtCity = new UITextField();
        txtCity.Placeholder = "Enter City";
        txtCity.BackgroundColor = UIColor.LightGray;

        UILabel lblState = new UILabel();
        lblState.Text = "State: ";

        UITextField txtState = new UITextField();
        txtState.TextColor = UIKit.UIColor.Blue;
        txtState.Text = "Select State";

        UILabel lblZip = new UILabel();
        lblZip.Text = "Zip: ";

        UITextField txtZip = new UITextField();
        txtZip.Placeholder = "Enter Zip";
        txtZip.BackgroundColor = UIColor.LightGray;

        UILabel lblPhone = new UILabel();
        lblPhone.Text = "Contact Phone:";

        UITextField txtPhone = new UITextField();
        txtPhone.Placeholder = "Enter Phone Number";
        txtPhone.BackgroundColor = UIColor.LightGray;

        UILabel lblSelectPhoneType = new UILabel();
        lblSelectPhoneType.Text = "Select Phone Type";

        UITextField txtSelectPhoneType = new UITextField();
        txtSelectPhoneType.Text = "Select Phone Type";
        txtSelectPhoneType.TextColor = UIKit.UIColor.Blue;

        UILabel lblMessage = new UILabel();
        lblMessage.Text = "Select Company (if applicable) and Department you are registering for.";
        lblMessage.TextColor = UIKit.UIColor.Blue;

        lblMessage.LineBreakMode = UILineBreakMode.WordWrap;

        UILabel lblSelectCompany = new UILabel();
        lblSelectCompany .Text = "Select Company (if applicable)";
        lblSelectCompany .TextAlignment = UITextAlignment.Center;


        // scrollView.ContentSize = CGSize(;
        scrollView.Add(lblUsername);
        scrollView.Add(txtUsername);

        scrollView.Add(lblPassword);
        scrollView.Add(txtPassword);
        scrollView.Add(lblConfirmPassword);
        scrollView.Add(txtConfirmPassword);
        scrollView.Add(lblEmailAddress);
        scrollView.Add(txtEmailAddress);
        scrollView.Add(lblConfirmEmailAddress);
        scrollView.Add(txtConfirmEmailAddress);
        scrollView.Add(lblSelectQuestion);
        scrollView.Add(challengeQuestion);
        scrollView.Add(lblAnswer);
        scrollView.Add(txtChallengeAnswer);

        scrollView.Add(lblFirstName);
        scrollView.Add(txtFirstName);
        scrollView.Add(lblMI);
        scrollView.Add(txtMI);
        scrollView.Add(lblLastName);
        scrollView.Add(txtLastName);
        scrollView.Add(lblSuffix);
        scrollView.Add(txtSuffix);
        scrollView.Add(lblAddress);
        scrollView.Add(txtAddress);
        scrollView.Add(lblCity);
        scrollView.Add(txtCity);
        scrollView.Add(lblState);
        scrollView.Add(txtState);
        scrollView.Add(lblZip);
        scrollView.Add(txtZip);
        scrollView.Add(lblPhone);
        scrollView.Add(txtPhone);
        scrollView.Add(lblSelectPhoneType);
        scrollView.Add(txtSelectPhoneType);
        scrollView.Add(lblMessage);
        scrollView.Add(lblSelectCompany);
        

        viewCreateAccount.Add(scrollView);

        scrollView.BackgroundColor = UIKit.UIColor.White;
        viewCreateAccount.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
        viewCreateAccount.AddConstraints
        (
            banner.AtTopOf(View, height),
            banner.AtRightOf(View, 0),
            banner.AtLeftOf(View, 0),

            lblTitle.Below(banner, 0),
            lblTitle.WithSameWidth(banner),

            scrollView.Below(lblTitle,0),
            scrollView.AtBottomOf(View,10),
            scrollView.AtLeftOf(View,10),
            scrollView.AtRightOf(View,10)
        );

        scrollView.SubviewsDoNotTranslateAutoresizingMaskIntoConstraints();
        scrollView.AddConstraints(
            lblUsername.AtTopOf(scrollView, 0),
            lblUsername.AtLeftOf(scrollView, 0),

            // txtUsername.Below(lblUsername, 0).Plus(5), // add below margin
            txtUsername.ToRightOf(lblUsername, 2),
            txtUsername.Width().EqualTo(250.0f),

            lblPassword.Below(lblUsername, 5),
            txtPassword.Below(lblUsername, 0).Plus(5), // add below margin
            txtPassword.ToRightOf(lblPassword, 2),
            txtPassword.Width().EqualTo(250.0f),

            lblConfirmPassword.Below(lblPassword, 5),
            txtConfirmPassword.Below(lblPassword, 0).Plus(5), // add below margin
            txtConfirmPassword.ToRightOf(lblConfirmPassword, 2),
            txtConfirmPassword.Width().EqualTo(250.0f),

            lblEmailAddress.Below(lblConfirmPassword, 5),
            txtEmailAddress.Below(lblConfirmPassword, 0).Plus(5), // add below margin
            txtEmailAddress.ToRightOf(lblEmailAddress, 2),
            txtEmailAddress.Width().EqualTo(250.0f),

            lblConfirmEmailAddress.Below(lblEmailAddress, 5),
            txtConfirmEmailAddress.Below(lblEmailAddress, 0).Plus(5), // add below margin
            txtConfirmEmailAddress.ToRightOf(lblConfirmEmailAddress, 2),
            txtConfirmEmailAddress.Width().EqualTo(250.0f),

            lblSelectQuestion.Below(lblConfirmEmailAddress).Plus(10),
            lblSelectQuestion.WithSameWidth(scrollView),

            challengeQuestion.WithSameWidth(scrollView),
            challengeQuestion.Below(lblSelectQuestion, 5).Plus(5),

            lblAnswer.Below(challengeQuestion, 5).Plus(5),
            lblAnswer.WithSameWidth(scrollView),

            txtChallengeAnswer.Below(lblAnswer).Plus(5),
            txtChallengeAnswer.WithSameWidth(scrollView),

            lblFirstName.Below(txtChallengeAnswer, 5),
            txtFirstName.Below(txtChallengeAnswer, 0).Plus(5), // add below margin
            txtFirstName.ToRightOf(lblFirstName, 2),
            txtFirstName.Width().EqualTo(250.0f),

            lblMI.Below(lblFirstName, 5),
            txtMI.Below(lblFirstName, 0).Plus(5), // add below margin
            txtMI.ToRightOf(lblMI, 2),
            txtMI.Width().EqualTo(50.0f),

            lblLastName.Below(lblMI, 5),
            txtLastName.Below(lblMI, 0).Plus(5), // add below margin
            txtLastName.ToRightOf(lblLastName, 2),
            txtLastName.Width().EqualTo(250.0f),

            lblSuffix.Below(lblLastName, 5),
            txtSuffix.Below(lblLastName, 0).Plus(5), // add below margin
            txtSuffix.ToRightOf(lblSuffix, 2),
            txtSuffix.Width().EqualTo(50.0f),

            lblAddress.Below(lblSuffix, 5),
            txtAddress.Below(lblSuffix, 0).Plus(5), // add below margin
            txtAddress.ToRightOf(lblAddress, 2),
            txtAddress.Width().EqualTo(250.0f),

            lblCity.Below(lblAddress, 5),
            txtCity.Below(lblAddress, 0).Plus(5), // add below margin
            txtCity.ToRightOf(lblCity, 2),
            txtCity.Width().EqualTo(250.0f),

            lblState.Below(lblCity, 5),
            txtState.Below(lblCity, 0).Plus(5), // add below margin
            txtState.ToRightOf(lblState, 2),
            txtState.Width().EqualTo(250.0f),

            lblZip.Below(lblState, 5),
            txtZip.Below(lblState, 0).Plus(5), // add below margin
            txtZip.ToRightOf(lblZip, 2),
            txtZip.Width().EqualTo(250.0f),

            lblPhone.Below(lblZip, 5),
            txtPhone.Below(lblZip, 0).Plus(5), // add below margin
            txtPhone.ToRightOf(lblPhone, 2),
            txtPhone.Width().EqualTo(200.0f),

            lblSelectPhoneType.Below(lblPhone, 5).Plus(5),
            lblSelectPhoneType.WithSameWidth(scrollView),

            txtSelectPhoneType.WithSameWidth(scrollView),
            txtSelectPhoneType.Below(lblSelectPhoneType, 5).Plus(5),

            //lblMessage.WithSameWidth(scrollView),
            lblMessage.Below(txtSelectPhoneType, 10).Plus(5),
            lblMessage.Width().EqualTo(350.0f),

            lblSelectCompany.Below(lblMessage, 5).Plus(5),
            lblSelectCompany.WithSameWidth(scrollView)

      );
        DataSet MyQuestionsDataset = myOMLService.GetQuestions(myusername, mypassword, "REGISTRATION", "EN");
        Questions.Add("Select Challenge Question");
        foreach (DataRow MyDataRow in MyQuestionsDataset.Tables[0].Rows)
        {
            Questions.Add(MyDataRow["QUESTION"].ToString());

        };


        ConfigureChallengePicker(challengeQuestion, Questions);

    }

    void ConfigureChallengePicker(UITextField pickerTextField, List<string> theData)
    {
        PickerViewModel MyModel = new PickerViewModel();
        MyModel._pickerSource = theData;
        var picker = new UIPickerView
        {
            Model = MyModel,
            ShowSelectionIndicator = true
        };
        var screenWidth = UIScreen.MainScreen.Bounds.Width;
        var pickerToolBar = new UIToolbar(new RectangleF(0, 0, (float)screenWidth, 44)) { BarStyle = UIBarStyle.Default, Translucent = true };
        var flexibleSpaceButton = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);
        var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, e) => pickerTextField.ResignFirstResponder());
        doneButton.Clicked += (object sender, EventArgs e) =>
        {
            pickerTextField.Text = MyModel.SelectedItem;
        };
        pickerToolBar.SetItems(new[] { flexibleSpaceButton, doneButton }, false);

        pickerTextField.InputView = picker;
        pickerTextField.InputAccessoryView = pickerToolBar;
    }
}

现在可以很好地滚动了,虽然帧尺寸有点大,但我必须想出一种方法来根据内容量来计算它,你会认为它是内置的,但不是。