user717452
user717452

Reputation: 111

External Display View Bounds to Match TV Resolution

I have my app set to be able to mirror to an AppleTV, and despite the constraints I have, about half of the bottom part of the PDF being displayed in the WKWebView is stretching past the bottom of the TV. The code I use and the warning dialog I get are below. The TV is 4K, as is the Apple TV, and I simply need it so that each page of the PDF in the WKWebView takes up the screen, even if some scaling is required.

 self.secondWindow = [[UIWindow alloc] init];
  self.secondWindow.screen = screen;
  self.secondWindow.screen.overscanCompensation = UIScreenOverscanCompensationScale;

  UIViewController *viewController = [[UIViewController alloc] init];
    self.secondWindow.rootViewController = viewController;
    viewController.view.frame=CGRectMake(0, 0, 1920, 1080);
    [self.secondWindow makeKeyAndVisible];
    WKWebView *theSongView = [[WKWebView alloc] init];
    [theSongView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [viewController.view addSubview:theSongView];
    theSongView.frame = CGRectMake(0, 0, 1920, 1080);
    
    UILayoutGuide *safeG = [viewController.view safeAreaLayoutGuide];

    [NSLayoutConstraint activateConstraints:@[
        [theSongView.topAnchor constraintEqualToAnchor:safeG.topAnchor],
        [theSongView.leadingAnchor constraintEqualToAnchor:safeG.leadingAnchor],
        [theSongView.trailingAnchor constraintEqualToAnchor:safeG.trailingAnchor],
        [theSongView.bottomAnchor constraintEqualToAnchor:safeG.bottomAnchor],
    ]];
   
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
       NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pdfPath = [[documentsDirectory stringByAppendingPathComponent:selectedCountry] stringByAppendingString:@".pdf"];
        NSURL *url = [NSURL fileURLWithPath:pdfPath];
        NSLog(@"%@",url);
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [theSongView loadRequest:request];
       
        timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];
        
   
}

Attempting to convert rect: {{0, 0}, {3840, 2160}} from <UIScreen: 0x104f45550; bounds = {{0, 0}, {3840, 2160}}; mode = <UIScreenMode: 0x2814a7300; size = 3840.000000 x 2160.000000>> (oriented) to <UIScreen: 0x104f06590; bounds = {{0, 0}, {834, 1194}}; mode = <UIScreenMode: 0x281482040; size = 1668.000000 x 2388.000000>> (oriented), which is not a valid conversion; returning CGRectNull.

Upvotes: 0

Views: 58

Answers (0)

Related Questions