4

I have a view with 4 text boxes and and a logo at the top - when the user is entering information the text pad covers up some of these controls, how can I make the view scroll so that this isn't an issue.

I have tried adding the view to a UIScrollView but that doesn't seem to do anything?

3 Answers3

0

I've included a snippit below of how I've handled your situation. If I'm understanding you correctly, you do not wish to have a scrollable view, rather you want to the view to move in conjunction with switching to and from fields to alleviate and visual hindrances caused by the keyboard.

Goodluck!

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();

    }
Nick Klufas
  • 218
  • 3
  • 9
0

You need to set more to the UIScrollView than just put subviews in it. Set up the ContentSize property properly for the complete size of the subviews so the scrollview knows about the larger content in it, than you can control the scrolling position, zoom factor and so on.

There are plenty of samples on iOS SDK, just check the UIScrollView documentation, transformation to Monotouch from ObjectiveC is straightforward or check blog post at http://blog.touch4apps.com/home/iphone-monotouch-development/monotouch-infinite-loop-image-scroll-view where I have a sample with images autoscrolled in UIScrollView.

Pavel Sich
  • 1,299
  • 10
  • 10
0

something like this.

textBox.EditingDidBegin += delegate {
  var offset = scrollView.contentOffset;
  offset.Y -= 200;
  scrollView.contentOffset = offset;
}
angel of code
  • 686
  • 8
  • 25