完成bool成功无法正常工作

时间:2014-02-19 21:47:55

标签: iphone objective-c animation boolean xcode5

我正在使用第二个视图控制器中的动画应用程序。动画结束后,我试图自动切换到下一个视图控制器。我有

中的segue

完成:^(BOOL成功){...

但它不起作用。然后我尝试了一个简单的NSLog @“......但是这也没用。我猜这个问题是BOOL没有完成或注册成功。动画我已经发生并完成......但完成BOOL是没有执行。请帮助。

来自secondViewController的.m文件......

#import "secondViewController.h"

@interface secondViewController ()

@property (nonatomic,weak) IBOutlet UIImageView *animatedImage;

@end

@implementation secondViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (void)viewDidAppear:(BOOL)animated
{
[self moveUp:nil finished:nil context:nil];
}
- (void)moveUp:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {

[UIView animateWithDuration:2.0
                      delay:1.0
 options:      (UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
                 animations:^{
                     [UIView setAnimationDelegate:self];
                     [UIView setAnimationDidStopSelector:@selector(moveDown:finished:context:)];
                     self.animatedImage.center = CGPointMake(160, 304);
                 }
                 completion:^(BOOL finished){
                     NSLog(@"Move up done");

                 }];


}

- (void)moveDown:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context {


[UIView animateWithDuration:2.0
                      delay:1.5
           options:  (UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
                 animations:^{
                     [UIView setAnimationDelegate:self];
                     [UIView setAnimationDidStopSelector:@selector(moveUp:finished:context:)];
                     self.animatedImage.center = CGPointMake(160, 775);

                 }
                 completion:^(BOOL finished){

                    [self performSegueWithIdentifier:@"backHome" sender:self];
                 }];
}

@end

2 个答案:

答案 0 :(得分:0)

您正在组合旧式和基于块的动画。不要那样做。

卸下

[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:...];

可能会解决问题。将完成逻辑放在完成块中。

答案 1 :(得分:0)

以下代码将是美观且可读的。

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated]; //Invoke super method
    [self doAnimation];
}

- (void)doAnimation{
    [UIView animateWithDuration:2.0
                      delay:1.0
                    options:(UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
                 animations:^{
                     self.animatedImage.center = CGPointMake(160, 304);
                 }
                 completion:^(BOOL finished){
                    [UIView animateWithDuration:2.0
                                          delay:1.5
                                        options:(UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
                                     animations:^{
                                           self.animatedImage.center = CGPointMake(160, 775);
                                     }
                                     completion:^(BOOL finished){
                                           [self performSegueWithIdentifier:@"backHome" sender:self];
                                     }
                   ];}

    }];
}