2011-04-21 99 views
10

在iphone应用程序/ ios中,我如何制作覆盖导航栏和键盘的透明“加载”覆盖图?在iphone应用/ ios中,如何制作覆盖导航栏和键盘的透明“加载”覆盖图?

我试过以下,但不包括任何的导航栏,也没有键盘:

UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; 
overlay.backgroundColor = [UIColor colorWithWhite:0 alpha:.5]; 
[self.view addSubview:overlay]; 

感谢

+0

它不包含导航栏,因为您需要将子视图添加到self.navigationController.view。有一个视图层次结构,例如1:顶部栏2:导航栏3:选项卡栏4:您的视图 – 2012-08-10 13:17:28

回答

6

如果您想要一个简单的库来照顾它,David Sinclair的DSActivityView是很好的。

+0

听起来不错,但他需要功劳,如果我们使用他的代码,并且我不确定应用程序中的位置学分! – Chris 2011-04-21 00:54:06

+0

@Chris当您提交代码时,您有机会修改与您的应用相关的**服务条款**。如果你希望你可以完全取代苹果公司默认使用的东西,但是我只是留下ToS,并添加与我使用的任何库相关的信用点和许可证。此外,在应用程序的网站上,我添加信用。在我看来,这两者相结合,但即使只是ToS修改也应该足够。 – 2011-04-21 03:34:41

2

它添加到self.view.window代替。这可能不包括键盘。在这种情况下,您需要创建自己的窗口。虽然这不是Apple推荐的。这意味着:在实施过程中要小心和彻底。

0

您可以尝试动作片,而不是用于加载透明观点:

actionSheetLoad = [[UIActionSheet alloc] initWithTitle:@"Loading..Please wait" delegate:nil cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil]; 

[actionSheetLoading showInView:showInView]; 

动作片将覆盖到时候后台任务的整个视图(说从服务器获取数据/击中URL)的运行。

3

有时当我懒得用其他库我只是这样做:

// create a custom black view 
UIView *overlayView = [[UIView alloc] initWithFrame:self.navigationController.view.frame]; 
overlayView.backgroundColor = [UIColor blackColor]; 
overlayView.alpha = 0.8; 
overlayView.tag = 88; 

// create a label 
UILabel *message = [[UILabel alloc] initWithFrame:self.navigationController.view.frame]; 
[message setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:25.0f]]; 
message.text = @"message to my dear user"; 
message.textColor = [UIColor whiteColor]; 
message.textAlignment = NSTextAlignmentCenter; 
message.tag = 99; 

// and just add them to navigationbar view 
[self.navigationController.view addSubview:overlayView]; 
[self.navigationController.view addSubview:message]; 

,然后调用发现这些观点的方法,淡化出来,并删除它们:

-(void) removeOverlayViews{ 
    UIView *view = (UIView *)[self.navigationController.view viewWithTag:88]; 
    UILabel *label = (UILabel *)[self.navigationController.view viewWithTag:99]; 

    [UIView animateWithDuration:0.5 
     animations:^{ 
      view.alpha = 0.0; 
      label.alpha = 0.0; 
     } 
     completion:^(BOOL finished){ 
      [view removeFromSuperview]; 
      [label removeFromSuperview]; 
     } 
    ]; 
} 

有时我只想显示一条消息几秒钟,所以我在为navigationController添加覆盖视图后立即打电话给我:

[self performSelector:@selector(removeOverlayViews) withObject:nil afterDelay:4]; 
+1

你先生是男人,这是更多的东西需要提供,而不是图书馆,当他们sooooooo不必要的,人们想知道如何做这些简单而轻松的事情,而不是一个图书馆,你让我的夜晚很多更容易谢谢你。从这我建立我自己的自定义微调加载覆盖;) – thekevshow 2014-11-14 05:33:51

+1

同意。请不要参考库的更多答案!实际上我们应该教导如何编写代码而不是如何使用预先构建的东西 – SPillai 2015-05-27 19:16:19