animateWithDuration完全没有运行

时间:2014-02-22 01:44:36

标签: ios objective-c uiviewcontroller uiviewanimation animatewithduration

我有一个没有autolayout的ViewController,我正在尝试为一些按钮设置动画。我在ViewDidAppear中有一些UIView animateWithDuration代码,其中的一切都很好用。但是,当我想要为视图制作动画时,没有任何动画。

这是代码序列。点击按钮,调用loginFacebook,登录到Facebook然后调用[self doneWithLogin]。 :

- (IBAction)loginFacebook:(id)sender {
        [self loginFacebook];
}

-(void)loginFacebook{
    //Login to Facebook to get name, photo

    NSArray *permissions = [[NSArray alloc] initWithObjects:
                            @"user_photos",
                            @"user_status",
                            nil];


       [FBSession openActiveSessionWithReadPermissions:permissions
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session,
                                                      FBSessionState state,
                                                      NSError *error) {

                                      if(!error){

                                          [self getFacebookData];
                                      }
                                      if(error){

                                          UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Oops." message: @"Something went wrong with Facebook." delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                                          [alert show];

                                      }

                                  }];

}

-(void)getFacebookData{
    if (FBSession.activeSession.isOpen) {
        [[FBRequest requestForMe] startWithCompletionHandler:
         ^(FBRequestConnection *connection,
           NSDictionary<FBGraphUser> *user,
           NSError *error) {
             if (!error) {

                 UserData *userData = [UserData sharedManager];
                 userData.userName = user.name;
                   NSString *photo = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=square", user.username];

                 userData.userPhoto = photo;

                 //now store data in nsuserdefault
                 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];


                 [defaults setObject:userData.userName forKey:@"name"];
                 [defaults setObject:userData.userPhoto forKey:@"photo"];

                 [defaults synchronize];

                 //should show animations and user info
                 [self doneWithLogin];

             }
             if(error){
                                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Oops." message: @"Something went wrong with Facebook." delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
                 [alert show];

             }
         }];


    }


}

-(void)doneWithLogin{
[SVProgressHUD dismiss];
UserData *userData = [UserData sharedManager];
NSLog(@"done with login called");
   NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];


[defaults setObject:@"YES" forKey:@"loggedIn"];
[[NSUserDefaults standardUserDefaults] synchronize];


NSLog(@"animation starting");
[UIView animateWithDuration: 1.0f
                      delay: 0.0f
                    options: UIViewAnimationOptionCurveEaseIn
                 animations:^{
                     logo.alpha = 0.0;
                     facebookButton.alpha = 0.0;
                     twitterButton.alpha = 0.0;
                     guestButton.alpha = 0.0;

                     NSLog(@"animation started");
                 }
                 completion:^(BOOL finished){
                     statusLabel.numberOfLines = 2;
                     statusLabel.lineBreakMode = NSLineBreakByWordWrapping;
                     statusLabel.text = [NSString stringWithFormat:@"Have a good time, %@", userData.userName];
                     [UIView animateWithDuration: 0.7f
                                            delay: 0.0f
                                          options: UIViewAnimationOptionCurveEaseIn
                                       animations:^{

                                           statusLabel.alpha = 1.0;
                                       }
                                       completion:^(BOOL finished){
                                           [self performSelector:@selector(dismissView:) withObject:self afterDelay:1];

                                       }
                                ];
                 }];

}

出现动画启动日志,但动画启动日志不会出现。没有任何动画,然后在一段时间后调用dismissView选择器。

知道发生了什么事吗?

1 个答案:

答案 0 :(得分:1)

您确定自己在doneWithLogin的主要队列中吗?我不熟悉FB API,但是当我看到flakey UIKit代码时,这是我检查的第一件事。