Tuesday 9 August 2011

iPhone SDK Troubles: Rotating scrollview image gallery



Everybody love iOS interface and its "magic" appeal: fluid rotations, fluid swipe, ecc. A iOS programmer knows that there's a lot of work under that magic. If you try to realize a simple image gallery, you'll have some surprises when you'll try to rotate it:

  1. your image will not be located on view's center, but on a corner.
  2. if you forced your gallery to scroll to a certain page with scrollToRect, then you'll see all your precedent images in a fast scroll, even if you set parameter Animated to NO
  3. if you need to scroll after rotation, you'll see a rotation around a corner
Solutions I found are:
  1. Point 1: when detecting a rotation, (willRotateToInterfaceOrientation), you have to resize:
    • Images on the scrollview
    • scrollview content

  2. Points 2 & 3: you must cover gallery's scrollview with a UIImageView containing current gallery image, hiding all scrollview animations. The "cover" will rotate around screen center, giving a more professional (and Apple) look.



No comments: