我正在尝试打开相机并将其显示在屏幕上(在我的视野内),同时让手电筒保持打开状态。
我遇到的问题是它在我第一次运行该应用程序时有效,但是当该应用程序进入后台然后进入前台时,相机卡住并显示最后一个 View 。
我做过的测试:
- 手电筒单独工作。
- 没有手电筒的相机在前景时工作。
我看到其他一些应用也有同样的问题。
有谁知道或能想到解决办法吗? (如果它能在 iOS5+ 上工作就足够了)
谢谢。
最佳答案
在控制相机和手电筒的 View Controller 中,将观察者添加到 UIApplicationDidBecomeActiveNotification
。
-(void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(becameActive) name:UIApplicationDidBecomeActiveNotification object:nil];
}
-(void)becameActive {
//this code runs when you resume a suspended application
//turn the camera torch on here
//assuming you already have this code
}
-(void)viewDidUnload {
[[NSNotificationCenter defaultCenter] removeObserver:self];
[super viewDidUnload];
}
关于iphone - 在 iOS 上同时使用手电筒和相机 - 在后台后不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10503336/