Help for retrieving UIView center please

Discussion in 'iOS Development' started by nicomook, Apr 21, 2008.

  1. nicomook

    nicomook New Member

    Joined:
    Apr 21, 2008
    Messages:
    2
    Likes Received:
    0
    Hello everybody,

    I just started developing IPhone apps.

    My problem is that I can't figure out how to know the position of an UIView.

    - I start an animation on a UIView (asking to go to another position in 5 seconds).
    - I have a thread which, 10 times per second, try to determine the position of the UIView.

    This is where I'm stucked.

    A call to CGPoint position = [sprite position] (where sprite is an UIImageView) doesn't compile:
    => error: invalid initializer
    If I use the 'frame' field of UIView, I have a weird result: x is 88 (instead of 100), y is -60 (instead of 460), furthermore, these coordinates doesn't change, even when the animation is being proceed.

    What am I doing wrong ?

    Thanks for reading me and helping me if you have any idea.

    --
    Cheers,
    Nico.
  2. gojohnnyboi

    gojohnnyboi Well-Known Member

    Joined:
    Jan 25, 2008
    Messages:
    3,339
    Likes Received:
    55

    if im correct, you set the position of THE WINDOW, not the view. You set the content view of the window for the view, so thats what u need.
  3. nicomook

    nicomook New Member

    Joined:
    Apr 21, 2008
    Messages:
    2
    Likes Received:
    0
    Hi,

    I set the position of the window, but I also set the position of the view I add into the window.

    I made a simple test.
    - I set the origin of a view
    - I start an animation of 5 seconds
    - I set the origin of the view to the destination I want.
    - I end the animation.
    => The animation works well, the view goes from it origin to the destination in 5 seconds.

    If I launch a thread that watches to the origin of the view, I always see the coordinates of the destination, even DURING the animation. I think the current "real" position is internal and not exposed by the framework. I don't think I can retrieve the position of a view, during an animation. All I can retrieve is the position of the view at the end of the animation.
    I fear I can't use animation and I have to set the position, step by step, by myself.

    Anyway thanks for your answer.

    Cheers,
    Nico.
  4. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    Look in the CoreGraphics framework. I know there's a way to get what you want. But since I've never had to do anything with it, I can't tell you off the top of my head.

    I'll look it up for you at some point after I get home from work today.

Share This Page