Order window out after toggling off full screen

Discussion in 'Mac Programming' started by abcdefg12345, Apr 19, 2015.

  1. abcdefg12345 macrumors regular

    abcdefg12345

    Joined:
    Jul 10, 2013
    #1
    I'm trying to toggle off full screen on window 1 and order it out then order window 2 front into the same location and size window 1 used to be, everything is working but after exiting full screen window 1 is not closing.

    Code:
    - (IBAction)myaction:(id)sender {
        
        // toggl off full screen if in full screen//
        if (([self.window styleMask] & NSFullScreenWindowMask)){
            [self.window toggleFullScreen:nil];
        }
        
        // set the second window size and location to be same as first window
        NSRect frame = [_window frame];
        [self.window2 setFrame:frame display:YES animate:NO];
        
        // open second window and close first window
        [_window2 orderFront:self];
        [_window orderOut:self];
    }
     
  2. abcdefg12345 thread starter macrumors regular

    abcdefg12345

    Joined:
    Jul 10, 2013
    #2
    found a workaround for the issue

    it seems that its cancelling out actions that are happening during the time where its switching from full screen to windowed mode

    after delaying the action for 1 second it seems to work as expected

    Code:
    - (IBAction)myaction:(id)sender {
        
        // toggl off full screen if in full screen//
        if (([self.window styleMask] & NSFullScreenWindowMask)){
            [self.window toggleFullScreen:nil];
            [self performSelector:@selector(closewindow1) withObject:nil afterDelay:1];
        }
        
        // set the second window size and location to be same as first window
        NSRect frame = [_window frame];
        [self.window2 setFrame:frame display:YES animate:NO];
        
        // open second window and close first window
        [_window2 orderFront:self];
        [_window orderOut:self];
    }
    
    -(void)closewindow1
    {
        [_window orderOut:self];
    }
    
     

Share This Page