Anc*_*inu 32 screenshot background uiapplicationdelegate ios ios7
我的应用程序中有保密信息,所以当应用程序即将移动到后台时,我想用启动画面隐藏它们.
我在iOS6上运行应用程序.
我试图显示视图,applicationWillResignActive但问题是它显示启动屏幕,即使用户滑动控制面板,例如.我希望它只在应用程序移动到后台时显示.
我尝试显示我的splashScreen,applicationDidEnterBackground但它需要screenShot才能在动画期间恢复时显示信息.
这就是我想要的精神:
- (void)applicationDidEnterBackground:(UIApplication *)application {
[_window addSubview:__splashController.view];
}
Run Code Online (Sandbox Code Playgroud)
Ash*_*hok 40
我认为问题是你在模拟器中测试.在设备上,它应该工作正常.
我测试过它并且有效.当应用进入后台时,添加带有启动图像的imageview -
- (void)applicationDidEnterBackground:(UIApplication *)application
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.window.bounds];
imageView.tag = 101; // Give some decent tagvalue or keep a reference of imageView in self
// imageView.backgroundColor = [UIColor redColor];
[imageView setImage:[UIImage imageNamed:@"Default.png"]]; // assuming Default.png is your splash image's name
[UIApplication.sharedApplication.keyWindow.subviews.lastObject addSubview:imageView];
}
Run Code Online (Sandbox Code Playgroud)
当应用程序回到前台时 -
- (void)applicationWillEnterForeground:(UIApplication *)application
{
UIImageView *imageView = (UIImageView *)[UIApplication.sharedApplication.keyWindow.subviews.lastObject viewWithTag:101]; // search by the same tag value
[imageView removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
注-在模拟器(的iOS 7.0),当您按下home键两次,按(Cmd + H)检查添加子视图中无法显示,但在设备能够正常运行(例如paypal,BofA应用程序)
编辑:(附加信息)
除了模糊/通过添加子视图/模糊如上所述取代敏感信息,的iOS 7提供你通过忽略该屏幕快照能力ignoreSnapshotOnNextApplicationLaunch的UIApplication内部applicationWillResignActive或applicationDidEnterBackground.
UIApplication.h
// Indicate the application should not use the snapshot on next launch, even if there is a valid state restoration archive.
// This should only be called from methods invoked from State Preservation, else it is ignored.
- (void)ignoreSnapshotOnNextApplicationLaunch NS_AVAILABLE_IOS(7_0);
Run Code Online (Sandbox Code Playgroud)
此外,allowScreenShot可以在限制有效负载中探索标志.
Swift 3.0为那些懒惰翻译的人提供答案.
func applicationDidEnterBackground(_ application: UIApplication) {
let imageView = UIImageView(frame: self.window!.bounds)
imageView.tag = 101
imageView.image = ...
UIApplication.shared.keyWindow?.subviews.last?.addSubview(imageView)
}
func applicationWillEnterForeground(_ application: UIApplication) {
if let imageView : UIImageView = UIApplication.shared.keyWindow?.subviews.last?.viewWithTag(101) as? UIImageView {
imageView.removeFromSuperview()
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16981 次 |
| 最近记录: |