0

我从其他 SO 问题中获取了一些代码,但我一定是在做一些奇怪的事情。应用程序从第一个视图跳转到第三个视图。我想要实现的是:

ViewController 1 Image 1 - 加载图像。快速交叉溶解到 ViewController 1 图像 2。

ViewController 1 Image 2 - 翻转到 ViewController 2。

交叉溶解发生了,但把我带到了 VC2。我在这一天的大部分时间里都在受挫。当我坐在浴缸里时,是时候寻求帮助了。

这是我一直在做的事情:

    - (void)viewDidLoad

        {
            NSLog(@"%s", __FUNCTION__);
            [super viewDidLoad];
        }

        - (void)viewDidAppear:(BOOL)animated {
            NSLog(@"%s", __FUNCTION__);

            sleep (2);
            [self transition1]; //showing image 1
        }

        - (void) transition1 {
            NSLog(@"%s", __FUNCTION__);
            /*
            [UIView transitionFromView:firstView
                          toView:secondView
                        duration:3.0
                         options:UIViewAnimationOptionTransitionCrossDissolve
                        completion:^(BOOL finished) {
                            [firstView removeFromSuperview];
                        }];
             */

            //this transition doesn't happen

UIImage * secondImage = [UIImage imageNamed:@"image2.png"];

[UIView transitionWithView:self.firstView
                        duration:5.0f
                         options:UIViewAnimationOptionTransitionCrossDissolve
                        animations:^{
                            self.imageView.image = secondImage;
                        } completion:NULL];



            sleep (2);
            [self transition2];
        }

        - (void) transition2 {
            NSLog(@"%s", __FUNCTION__);
            self.patterns = [[PatternViewController alloc] initWithNibName:@"PatternView_iPad" bundle:nil];
            self.patterns.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            [self presentViewController:patterns animated:YES completion:nil];
        }

谢谢你的帮助。

更新

我根据 Moxy 的建议更新了我的代码,如下所示:

- (void)viewDidAppear:(BOOL)animated {
    NSLog(@"%s", __FUNCTION__);
    [self performSelector:@selector(transition1)
             withObject:nil
             afterDelay:2.0f];
}

-(void)transition1
{
    NSLog(@"%s", __FUNCTION__);
    UIImage * secondImage = [UIImage imageNamed:@"image2.png"];
    [UIView transitionWithView:self.firstView
                duration:5.0f
                 options:UIViewAnimationOptionTransitionCrossDissolve
                animations:^{
                            self.imageView.image = secondImage;
                }
                completion:^(BOOL finished){
                            [self performSelector:@selector(transition2)
                                       withObject:nil
                                       afterDelay:2.0f];
                }];
}

-(void)transition2
{
    NSLog(@"%s", __FUNCTION__);
    self.patterns = [[PatternViewController alloc] initWithNibName:@"PatternView_iPad"
                                          bundle:nil];
    self.patterns.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentViewController:patterns
                 animated:YES
                 completion:nil];
}
4

1 回答 1

3

您需要做的就是在第一个动画的完成块中开始您的第二个动画。Sleep() 是您可能不应该使用的东西。

-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    NSLog(@"%s", __FUNCTION__);
    [self performSelector:@selector(transition1)
               withObject:nil
               afterDelay:2.0f]
}

-(void)transition1
{
    NSLog(@"%s", __FUNCTION__);
    UIImage * secondImage = [UIImage imageNamed:@"image2.png"];
    [UIView transitionWithView:self.firstView
                      duration:5.0f
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:^{
                            self.imageView.image = secondImage;
                    }
                    completion:^(BOOL finished){
                            [self performSelector:@selector(transition2)
                                       withObject:nil
                                       afterDelay:2.0f]
                     }];
}

-(void)transition2
{
    NSLog(@"%s", __FUNCTION__);
    self.patterns = [[PatternViewController alloc] initWithNibName:@"PatternView_iPad" 
                                                            bundle:nil];
    self.patterns.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentViewController:patterns
                       animated:YES
                     completion:nil];
}
于 2013-03-03T00:17:27.480 回答