Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 连续翻转视图_Iphone_Core Animation - Fatal编程技术网

Iphone 连续翻转视图

Iphone 连续翻转视图,iphone,core-animation,Iphone,Core Animation,这是我的密码 [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.5]; if ([sender tag] == 1) { [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:placeholder cache:YES]; } else {

这是我的密码

[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;
我想连续翻转视图,比如说持续1分钟

它应该不断地翻转

我该怎么做呢。 我想说的是,我想要一个视图,它应该在特定的时间内持续翻转。 我怎样才能做到这一点?
关于

除了翻转动画(我认为您正在工作)之外,您需要在当前动画完成后启动一个新动画

在[UIView commitAnimations]之前,请执行以下操作:

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(animationDone:finished:context:)];
添加一个函数

-(void)animationDone:(NSString*)id finished:(NSNumber*)n context:(void*)context
让它点燃下一轮

编辑:您可以通过输入启动动画的代码来执行此操作,因此典型的块从
[UIView beginAnimations…]
[UIView commitAnimations]
。当然,更好的解决方案是将动画开始代码放在一个单独的函数中,因此大纲如下所示:

...
    [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];
}

要使其来回运行,请添加一些状态变量,或创建两组相互调用的函数(
startAnimationLoop1
startAnimationLoop2
,完成后,每一个都会触发另一个)

谢谢mvds我只想知道一件事,我应该在animationdone函数中写些什么。??编辑答案使其更明确。此外,我建议你去试验,所有的成分都在那里。