iOS开发-自定义后台显示图片

有一些应用在我们双击HOME键进入到App Switcher显示的界面的时候会有一张图片覆盖住App Switcher。这就涉及到了Background Fetch。

下面我就介绍一下具体的实现过程:

1.配置后台模式



2.在AppDelegate.h中添加代码

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. @property (strong, nonatomic) UIImageView *backView;  

3.在AppDelegate.m中添加代码

[cpp]  view plain copy 在CODE上查看代码片 派生到我的代码片
  
  1. #import "AppDelegate.h"  
  2.   
  3. @implementation AppDelegate   
  4.   
  5. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions  
  6. {  
  7.     // Override point for customization after application launch.  
  8.       
  9.     [application setMinimumBackgroundFetchInterval:UIApplicationBackgroundFetchIntervalMinimum];  
  10.   
  11.     [self.window makeKeyAndVisible];  
  12.     backView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 568)];  
  13.     [backView setImage:[UIImage imageNamed:@"***.png"]];  
  14.       
  15.     return YES;  
  16. }  
  17.   
  18. - (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler  
  19. {  
  20.     NSLog(@"后台获取");  
  21.     completionHandler(UIBackgroundFetchResultNewData);  
  22. }  
  23.         
  24. - (void)applicationDidEnterBackground:(UIApplication *)application  
  25. {  
  26.       
  27.     [self.window addSubview:backView];  
  28.     [self.window bringSubviewToFront:backView];    
  29. }  
  30.   
  31. - (void)applicationWillEnterForeground:(UIApplication *)application  
  32. {  
  33.   
  34.     [self.backView removeFromSuperview];  
  35.     // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.  
  36. }  
  37.     
  38. @end  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值