UIViewAnimation Mirroring/Looping?

Discussion in 'iOS Development' started by cocotutch, Oct 16, 2009.

  1. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    I have been looking this up and trying different ways to do this. So please don't say use the Docs, I have the code to make the animation work, I just want it to Mirror Loop.

    Example:

    I am translating a Label -960px, I want it to do that, then automatically return back to 0px before repeating again etc, etc.

    I have this so far:

    [OBJC]if(looping == YES) {
    [UIView beginAnimations

    Please Register or Log in to view images

    "TouchDownAnimation" context:NULL];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:genre.text.length];
    CGAffineTransform transform6 = CGAffineTransformMakeTranslation(0, 0);
    genre.alpha = 0.2;
    genre.transform = transform6;
    [UIView commitAnimations];
    looping = NO;
    }
    else {
    [UIView beginAnimations

    Please Register or Log in to view images

    "TouchDownAnimation" context:NULL];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:genre.text.length];
    CGAffineTransform transform6 = CGAffineTransformMakeTranslation(-960, 0);
    //[self.view addSubview

    Please Register or Log in to view images

    verlay_controls];
    // [UIView setAnimationRepeatCount:1e100f];
    genre.alpha = 0.0;
    genre.transform = transform6;
    //genre.bounds = CGRectMake(genre.text.length, 100, 0, 0);
    [UIView commitAnimations];
    looping = YES;
    }[/OBJC]
    That is the block of code I want to continually loop, using that idea above. But all it does is do the first -960px translation, then it doesn't come back. Can anyone help me? I have been on this for like 4 hours now, and I can't find anything on Google.

    Thanks,

    cocotutch
  2. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    Explain the animation you want to do. Like are you moving it down, then when you release your finger the label moves back?
  3. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    [OBJC]
    + (void)setAnimationRepeatCount

    Please Register or Log in to view images

    float)repeatCount

    + (void)setAnimationRepeatAutoreverses

    Please Register or Log in to view images

    BOOL)repeatAutoreverses
    [/OBJC]

    That will eliminate all that redundant code up there. And yes, those two methods are posted in the UIView class reference.
  4. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    Thanks,

    I will have a look soon, im making my lunch atm...

    Please Register or Log in to view images


    ------------------double post merged------------------
    Thankyou, It worked wonderfully.

    Another quick question, would I be able to change the size of the UITextField according to how long the word is? And have the Animation Translate to the length of it?

    i.e. genre.bounds = CGRectMake(genre.text.length, 100, 0,0);

    coco
  5. cocotutch

    cocotutch Community Development Team Staff Member

    Joined:
    Oct 6, 2008
    Messages:
    1,285
    Likes Received:
    117
    Device:
    5G iPod touch
    I have utilised this code like this:

    Please Register or Log in to view images


    IMG_0276.PNG IMG_0277.PNG IMG_0278.PNG
    Like the ZuneHD-esque UI?

    coco
  6. Steaps

    Steaps New Member

    Joined:
    Oct 24, 2007
    Messages:
    5,074
    Likes Received:
    41
    Device:
    iPod touch
    It's [genre.text length] for a NSString.
  7. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    genre.text.length does in fact work. It's invoking/calling those methods. Dot syntax (in Obj-C) is screwy.

    Please Register or Log in to view images

  8. God__

    God__ New Member

    Joined:
    Dec 23, 2007
    Messages:
    69
    Likes Received:
    0
    So... The OP here specifically told everybody to not tell him to search the docs. Then the second reply pulls two simple methods straight out of the docs that solve the quandry? Clearly I can't be the only one who finds this sad.

    Of course, it's easy to miss. The two methods presented appear in two separate places in the documentation Apple povides.

    You, my child, must slow yourself down some. Take a moment to think about where you are and what you are doing. This applies to all aspects of life. And when all else fails, look at the documentation.

    I've noticed in other threads that you seem to fight the notion that your solution could be in the docs. Why? This is not a rhetorical question.
  9. Axis

    Axis Super Moderator Staff Member

    Joined:
    Dec 2, 2007
    Messages:
    6,288
    Likes Received:
    133
    Device:
    iPhone 4S (White)
    He obviously did not read the documentation well enough to see those two methods, which, are in a section entitled "Animating Views". I'm assuming your statement was a cut at me, in which case I don't understand your point at all.

    I do realize that the OP specifically said not to tell him to read the docs. He has said this in all the threads started by him that I can remember. More often than not, the answer was in fact, straight from the docs. That pattern continued itself in this thread. I don't know what's wrong with me ignoring his foolish "documentation is an insult to my intelligence" attitude and saving everyone some time.


    EDIT: My interpretation failed, just re-read your post

    Please Register or Log in to view images



    Not that it matters all that much, but those two methods are adjacent in the UIView Class reference.

    Please Register or Log in to view images

  10. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    I'm fairly certain he's implying that both of those methods appear in two places within the docs. Because they do.

Share This Page