Xamarin.ios Monotouch-使UIView可滚动

Xamarin.ios Monotouch-使UIView可滚动,xamarin.ios,Xamarin.ios,我有一个视图,上面有4个文本框和一个徽标-当用户输入信息时,文本板会覆盖其中的一些控件,如何使视图滚动以避免出现问题 我已尝试将视图添加到UIScrollView中,但这似乎没有任何作用?您需要对UIScrollView进行更多设置,而不仅仅是在其中放置子视图。为子视图的完整大小正确设置ContentSize属性,以便scrollview了解其中较大的内容,而不是控制滚动位置、缩放因子等 iOS SDK上有很多示例,只需查看UIScrollView文档,从ObjectiveC到Monotouch

我有一个视图,上面有4个文本框和一个徽标-当用户输入信息时,文本板会覆盖其中的一些控件,如何使视图滚动以避免出现问题


我已尝试将视图添加到
UIScrollView
中,但这似乎没有任何作用?

您需要对UIScrollView进行更多设置,而不仅仅是在其中放置子视图。为子视图的完整大小正确设置ContentSize属性,以便scrollview了解其中较大的内容,而不是控制滚动位置、缩放因子等

iOS SDK上有很多示例,只需查看UIScrollView文档,从ObjectiveC到Monotouch的转换非常简单,或者查看我的博客文章,在那里我有一个在UIScrollView中自动克隆图像的示例。

类似的内容

textBox.EditingDidBegin += delegate {
  var offset = scrollView.contentOffset;
  offset.Y -= 200;
  scrollView.contentOffset = offset;
}

我在下面写了一篇关于我如何处理你的情况的短评。如果我理解正确,您不希望有一个可滚动的视图,而是希望视图与字段之间的切换一起移动,以减轻键盘造成的视觉障碍

祝你好运

private void ScrollTheView(bool movedUp, float scrollamount, UIView ViewToMove)
    {
        //To invoke a views built-in animation behaviour,
        //you create an animation block and
        //set the duration of the move...
        //Set the display scroll animation and duration...
        UIView.BeginAnimations(string.Empty, System.IntPtr.Zero);
        UIView.SetAnimationDuration(0.15);

        //Get Display size...
        RectangleF frame = ViewToMove.Frame;

        if (movedUp) {
            //If the view should be moved up,
            //subtract the keyboard height from the display...
            frame.Y -= scrollamount;
        }
        else {
            //If the view shouldn't be moved up, restore it
            //by adding the keyboard height back to the original...
            frame.Y += scrollamount;
        }

        //Assign the new frame to the view...
        ViewToMove.Frame = frame;

        //Tell the view that your all done with setting
        //the animation parameters, and it should
        //start the animation...
        UIView.CommitAnimations();

    }