C6Silver
C6Silver

Reputation: 3357

How a ViewController can recognize when it is NOT onscreen

I have two viewcontrollers which we will call VC1 and VC2. VC1 is a splitscreencontroller that presents VC2 full-screen modal when an image or video is tapped. VC1 implements: -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation When VC2 is onscreen and the user rotates the device, this is recognized in the VC1 method above which is executed. However, I have some code in that VC1 method that I don't want to execute if VC1 is not on screen. It is otherwise fine, and indeed necessary, that the rotation method of VC1 is called.

What is the best way for VC1 to identify when it is not onscreen such that I can put an if statement in the rotate method that will then only execute certain statements if VC1 is actually onscreen?

Upvotes: 0

Views: 46

Answers (1)

dan
dan

Reputation: 9825

You can check if the view controller's view has a window to see if it is onscreen.

if (vc1.view.window != nil) {
    // view is onscreen
}

Upvotes: 2

Related Questions