• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

c# - UIScrollView 滚动不工作 Xamarin IOS

[复制链接]
菜鸟教程小白 发表于 2022-12-13 08:44:18 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

创建添加到UIViewController View的 ScrollView

UIScroll scroll_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 个文本字段和一个提交按钮。添加到 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。



Best Answer-推荐答案


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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap