UIScrollView. Moving the "camera"

Discussion in 'iOS Programming' started by Molten, Oct 20, 2009.

  1. macrumors newbie

    Oct 20, 2009
    Hello, I'm struggling with moving the view of my UIScrollView programmatically (showing different regions inside the UIScrollView).
    To make it simple:

    1x UIScrollView
    2x UIImageView (a gamefield) & (a playerunit).

    So i set up my gamefield in the UIScrollView (this is bigger than the visible region of the UIScrollView, so i can pan and zoom etc)

    And i set up my player unit in the UIScrollview, above the gamefield.

    so now to the problem. When my playerUnit goes outside the bounds of my UIScrollView the camera doesn't move, and this is frankly ok, i just pan to where it is.
    But, when i pan around the map, i don't want to go and search for my playerUnit, and I've therefore put a IBAction set up to a UIButton.
    I want this IBAction to place the "camera" (view region of my UIscrollview) to have my PlayerUnit centered.

    Thankful for all responses! :)
  2. macrumors 68000

    Feb 12, 2008
    UIScrollView has a setContentOffset: animated:

    So I think putting in the center of the playerunit will do (if not, then play around with it).

    Note you can use this to actually keep the scrollview scrolling as the player moves if you wanted.

    I was wondering, is this going to be a graphic/animation heavy game? Enough views in scrollviews will impact the performance dramatically compared to OpenGL.
  3. thread starter macrumors newbie

    Oct 20, 2009
    Thanks for the answer :)

    No the game wont be graphic heavy, or in not in the manner of extensive animations and redrawn images.

    The game consists of a predrawn gamefield, with x amount of images in the size of ~ 50x50 -to- 200x200 px.
    And there will be around 5-6 animated images (not heavily animated) wich serve as player and computer units.

    What i've seen on the simulator (i know this is not remotely true to the performance on the actual device ) the game runs smoothly with some minor bugs and code related failures.
  4. macrumors member

    Aug 19, 2008
    You can use

    - (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated

Share This Page