1

我有一个带有登录屏幕的应用程序,其中包含一个登录按钮和一个注册按钮,如果我检测到我无法访问互联网,则使用可达性我通过显示覆盖视图来隐藏这些按钮

 self.coveringview

现在我用这个视图的 alpha 做一些简单的动画,一旦完成,我希望弹出一个 alertview 来告诉用户发生了什么,在这段代码中你可以看到我正在通过在animatewithduration 的完成块。

bahvior 不是我想要的,警报弹出太快而没有向用户显示我希望它显示的淡出,我该怎么办?

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;
                   }];
}
4

2 回答 2

1

self.coveringView.hidden = YES从您的 Interface Builder 中删除并设置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;
                      }
                   }];
于 2013-10-23T00:48:55.577 回答
0

您不需要同时使用 setHidden 和 0.0 的 alpha 它们都会使视图不会拦截触摸。您的 hidden/notHidden 可能与 alpha 更改发生冲突。

尝试像这样简化:

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) {
                   }];
}
于 2013-10-23T01:40:07.950 回答