Reputation: 1009
I have an app with a login screen that hosts a sign in button and a sign up button, using reachibility if I detect that I can't reach the internet I hide those buttons by showing a covering view
self.coveringview
Now I do some simple animation playing with the alpha of this view, once that is done, I want an alertview to popup to tell the user what happen, in this code you can see I am doing that by having the alert.show in the completion block of the animatewithduration.
the bahvior is not what I want, the alert pops up too fast without showing the user the fade out I want it to show, what can I do?
NetworkStatus netStatus = [reachability currentReachabilityStatus];
if(netStatus == NotReachable) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection"
message:@"Unable to connect to the server.
Please check your internet connection and try again."
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[UIView animateWithDuration:1.0
animations:^{
self.coveringView.alpha = 1.0;
}completion:^(BOOL finished) {
// this is the problem here, I need to make this alert show up after
the fade out occurs completely
[alert show];
self.coveringView.hidden = NO;
}];
}
else {
[UIView animateWithDuration:1.0
animations:^{
self.coveringView.alpha = 0.0;
}completion:^(BOOL finished) {
self.coveringView.hidden = YES;
}];
}
Upvotes: 1
Views: 629
Reputation: 3850
remove your self.coveringView.hidden = YES
from your Interface Builder and set just alpha = 0
NetworkStatus netStatus = [reachability currentReachabilityStatus];
if(netStatus == NotReachable) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection"
message:@"Unable to connect to the server.
Please check your internet connection and try again."
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[UIView animateWithDuration:1.0
animations:^{
self.coveringView.alpha = 1.0;
}completion:^(BOOL finished) {
// this is the problem here, I need to make this alert show up after the fade out occurs completely
if(finished){
[alert show];
}
}];
}
else {
[UIView animateWithDuration:1.0
animations:^{
self.coveringView.alpha = 0.0;
}completion:^(BOOL finished) {
if(finished){
self.coveringView.hidden = YES;
}
}];
Upvotes: 1
Reputation: 11083
You don't need to use both setHidden and an alpha of 0.0 They both will make the view so that it doesn't intercept touches. Your hidden/notHidden is likely conflicting with the alpha changes.
Try simplifying like this:
NetworkStatus netStatus = [reachability currentReachabilityStatus];
if(netStatus == NotReachable) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Internet Connection"
message:@"Unable to connect to the server.
Please check your internet connection and try again."
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"OK", nil];
[UIView animateWithDuration:1.0
animations:^{
self.coveringView.alpha = 1.0;
}completion:^(BOOL finished) {
//I need to make this alert show up after the fade out occurs completely
[alert show];
}];
}
else {
[UIView animateWithDuration:1.0
animations:^{
self.coveringView.alpha = 0.0;
}completion:^(BOOL finished) {
}];
}
Upvotes: 0