fliping view continiously

ぐ巨炮叔叔 提交于 2019-12-12 04:37:13

问题


this my code

[UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1.5];  
    if ([sender tag] == 1) {
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:placeholder cache:YES];
    }
    else {
        [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
    }
    if (view1OnTop) {
        [view1 removeFromSuperview];
        [placeholder addSubview:view2];
    }
    else {
        [view2 removeFromSuperview];
        [placeholder addSubview:view1];
    }
    [UIView commitAnimations];

    view1OnTop = !view1OnTop;

i want to continuously flip the view, for say some duration 1 min.

it should be continuously flipping.

how can i do it. what i m trying to is, i want a view, which should be continuously flipping for some particular amount of time. how can i achieve this? regards


回答1:


Apart from the flipping animation, which I presume you have working, you need to initiate a new animation when the current one is finished.

Before [UIView commitAnimations], do this:

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDone:finished:context:)];

add a function

-(void)animationDone:(NSString*)id finished:(NSNumber*)n context:(void*)context

and let that fire the next round.

edit: you do this by putting in the code to fire an animation, so the typical block from [UIView beginAnimations...] to [UIView commitAnimations]. The better solution of course is to put the animation starting code in a separate function, so the outline will look like:

...
    [self startAnimationLoop];
...

-(void)startAnimationLoop
{
    [UIView beginAnimtions...];

    // do the animation stuff

    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(animationDone:finished:context:)];
    [UIView commitAnimations];
}

-(void)animationDone:(NSString*)id finished:(NSNumber*)n context:(void*)context
{
    [self startAnimationLoop];
}

to make it go back/forth, add some state variable, or create 2 sets of these functions which call eachother (startAnimationLoop1 and startAnimationLoop2, each one firing the other when done)



来源:https://stackoverflow.com/questions/3253310/fliping-view-continiously

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!