0

我有一个没有自动布局的 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 选择器。

知道发生了什么吗?

4

1 回答 1

1

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

于 2014-02-22T05:20:31.247 回答