Domanda

I have a ViewController WITHOUT autolayout, and I'm trying to animate some of the buttons. I have some UIView animateWithDuration code in the ViewDidAppear, and everything there works great. But when I want to animate the view out, nothing animates.

Here's the code sequence. Button tapped, calls loginFacebook, that logs into Facebook and then [self doneWithLogin] is called. :

- (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];

                                       }
                                ];
                 }];

}

The animation starting log appears, but the animation started log doesn't. Nothing animates, and then after some time the dismissView selector is called.

Any idea what's going on?

È stato utile?

Soluzione

Are you sure you're on the main queue in doneWithLogin? I'm not familiar with the FB APIs, but when I see flakey UIKit code, that is one of the first things I check.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top