views:

186

answers:

1

Hi,

Sorry for long winded post.

I am trying to understand UIScrollView and running into very simple problem.

  1. I am creating a scroll view
  2. I am making this view 1.5 size larger then normal size
  3. Using UIScrollView I expect to see some edge elements of view out of bounds, but should be able to pan the view therefore bringing missing elements back to the visible area.

However I am seeing that I can't just pan/scroll view anyway I want, instead view always wants to scroll up, as soon as move away my finger from the screen (touch end event).

I am not handling any touches, etc - I just want to understand why does not scaled view stay put where I scroll it?

CGRect viewFrame = self.view.frame ;
    viewFrame.size.width *= 1.5;
    viewFrame.size.height *= 1.5;
    CGSize mySize = viewFrame.size;

    [ ((UIScrollView *) self.view) setContentSize: mySize];

    self.view.transform =   CGAffineTransformMakeScale(1.5, 1.5);

What I really trying to accomplish is something similar to Number on iPad (the same code will work on iPhone):

  • There is a view with lots of controls on it (order entry form)
  • User can zoom into the entire form so all elements look bigger
  • user can pan the form therefore bringing various elements into the visible area of the screen.

It seems that UIScrollView can should be able to handle zoom and pan actions (for now I am using Affine Transform to zoom in to the order entry form and iPad)

Thanks

+1  A: 

When you transform a view, you transform its internal coordinate system as well. This means that if you scale a view, the view still "thinks" it is the same size it was before the scale because its coordinate units scaled as well.

For example, if you have an image view that has a size of (50,50) and you transform it so that it covers (200,200) on the screen, when you ask the image view its size it will report that its size is still (50,50).

Scrollviews are unusual types of views because they have understand their absolute size relative to physical device screen in order to work properly. When you transform their coordinate system, they lose that connection to the physical device screen and can no longer function properly. This is what you are seeing.

I haven't done this but I'm pretty sure to create the illusion of a zoom in a scrollview, you increase the frame of the scrollview and then transform its subviews (or transform the subviews and then increase the frame of the scrollview to contain the new subview size.) That is the only way to keep the scrollview in sync with the physical device screen.

TechZen
I totally overlooked the fact that coordinate system changes!! Thanks. I will look into scroll view build-in facility for panning and zooming
leon