2

最新の SDK を使用して iOS アプリを開発しています。

フルスクリーンアプリです。

viewWillAppearアプリがバックグラウンドから来るたびに呼び出す必要があるメソッド上のメソッドがあります。

- (void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self setUpVideo];
}

アプリがバックグラウンドから戻ったときにビデオが失われるため、setUpVideoセットアップしました。AVCaptureVideoPreviewLayer

私が読んだviewWillAppearように、アプリがバックグラウンドから戻ったときに呼び出されず、そのコードをどこに置くべきかわかりません。

この質問では、オクルスは使用を提案しています[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doMyLayoutStuff:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];が、私にはうまくいきません。

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setUpVideo:) name:UIApplicationDidChangeStatusBarFrameNotification object:nil];
}

何かアドバイス?

4

3 に答える 3

4

UIApplicationWillEnterForegroundNotification代わりに観察してください。

- (void)viewDidAppear {
    [super viewDidAppear];
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(enterForeground:) 
              name:UIApplicationWillEnterForegroundNotification 
              object:nil];
    // ...
}

- (void)enterForeground:(NSNotification *)notification {
    // do stuff
}

メソッドviewWillAppear:から直接呼び出さないでください。enterForeground:代わりに、必要なすべてのコードを別のメソッドに移動し、 と の両方から呼び出しviewWillAppear:ますenterForeground:

于 2013-03-21T10:30:28.277 に答える
1
applicationWillEnterForeground will trigger when app comes from background

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

UIApplicationDidBecomeActiveNotificationさらに、いくつかのメソッドを起動するために使用できます

[[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(handleMethod:)
                                                 name: UIApplicationDidBecomeActiveNotification
                                               object: [UIApplication sharedApplication]];
于 2013-03-21T10:30:33.890 に答える
0

この通知 - (void)applicationDidBecomeActive:(UIApplication *)applicationを AppDelegate から投稿してみてください (または、対応する通知を確認してください)。

于 2013-03-21T10:29:55.077 に答える