我有一个没有自动布局的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选择器。
知道发生了什么吗?
最佳答案
您确定您在doneWithLogin
的主队列中吗?我对FB API并不熟悉,但是当我看到Flakey UIKit代码时,这是我首先检查的内容之一。
关于ios - animateWithDuration根本不运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21948540/