c# - UIScrollView 滚动不工作 Xamarin IOS

标签 c# ios uiscrollview xamarin.ios xamarin

创建添加到UIViewController View 的 ScrollView

UIScroll滚动_View;

scroll_View = new UIScrollView {
            BackgroundColor = UIColor.Black,
            Frame = View.Frame,
            ContentSize =  new SizeF(320,720),
        };
View.addSubView(scroll_View);// Added to Regisration ViewController

//创建文本字段

        firstName = new UITextField {
            Placeholder = "Enter firstName",
            BorderStyle = UITextBorderStyle.None,
            VerticalAlignment = UIControlContentVerticalAlignment.Center,
            AutocorrectionType = UITextAutocorrectionType.No,
            AutocapitalizationType = UITextAutocapitalizationType.None,
            ClearButtonMode = UITextFieldViewMode.WhileEditing,
            Background = TextFieldBackground,
            LeftView = new UIView (new RectangleF (0, 0,8, 8)),
            LeftViewMode = UITextFieldViewMode.Always,
            ReturnKeyType = UIReturnKeyType.Next,
            ShouldReturn = delegate {
                lastName.BecomeFirstResponder ();
                return true;
            }

        };

//这样就创建了 9 个文本字段和 1 个提交按钮。添加到ScrollView

框架文本字段。

firstName.Frame =   new RectangleF(80, 20, 200, 41);
lastName.Frame =    new  RectangleF(80, 70, 200, 41);
middle.Frame =  new  RectangleF(80, 120, 200, 41);
email.Frame =   new  RectangleF(80, 127, 200, 41);
password.Frame =    new  RectangleF(80, 220, 200, 41);
conformPassword.Frame = new  RectangleF(80, 270, 200, 41);
phoneNumber.Frame = new  RectangleF(80, 320, 200, 41);
description.Frame = new  RectangleF(80, 370, 200, 41);
other.Frame =   new  RectangleF(80, 420, 200, 41);
buttonSubmit.Frame =    new  RectangleF(80, 470, 420, 41);

向 ScrollView 添加文本字段

scroll_View.addSubView(firstName); 
scroll_View.addSubView(lastName); 
scroll_View.addSubView(middleName);
scroll_View.addSubView(email); 
scroll_View.addSubView(Password); 
scroll_View.addSubView(conformaPassword); 
scroll_View.addSubView(phoneNumber); 
scroll_View.addSubView(description); 
scroll_View.addSubView(other); 
scroll_View.addSubView(buttonSubmit); 

添加了 ScrollView UIViewController View 。

    View.AddSubview (scroll_View);

滚动时滚动效果不起作用。 Xamarin IOS。

最佳答案

public override void ViewDidLoad ()
{

    base.ViewDidLoad ();

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

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

    for (int i=0; i<n; i++) {
        var button = UIButton.FromType (UIButtonType.RoundedRect);
        button.SetTitle (i.ToString (), UIControlState.Normal);
        button.Frame = new RectangleF (padding * (i + 1) + (i * w), padding, w, h);
        _scrollView.AddSubview (button);
        _buttons.Add (button);
    }

    View.AddSubview (_scrollView);
}

关于c# - UIScrollView 滚动不工作 Xamarin IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24821658/

相关文章:

ios - 在未排序的子节点上运行操作

objective-c - 多个可滚动 subview / TableView

c# - 在不缓存数据的情况下覆盖 ActionResult

c# - 通用约束

ios - Obj-C - 带有图像的数组上的if语句

ios - 如何更新框架的高度?

ios - 如何在 ScrollView 中将图像置于最前面

c# - 如何在 C# 中比较字符串和枚举

c# - 方法依赖 - 最佳实践?

ios - 带有 "where"的协议(protocol)导致崩溃