0

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.

user717452
  • 33
  • 14
  • 73
  • 149
  • If you put together a [mre] and post it on GitHub or similar, it will be much easier to try to help. – DonMag Aug 03 '22 at 22:16
  • https://www.mediafire.com/file/ruc2o2gzxy3h7du/MINIMAL.zip/file @DonMag – user717452 Aug 03 '22 at 23:29
  • Not really clear what you're goal is... The web view is **not** stretching below the bottom of the screen. Here's what I get when I inset the web view a little bit: https://i.stack.imgur.com/u56jW.png -- and here's what I get when I make the web view 200-points wide, 80-points from Top/Bottom: https://i.stack.imgur.com/6ScGq.png – DonMag Aug 04 '22 at 12:41
  • @DonMag but as you can tell from the one where all of the pdf was visible, there’s quite a bit on the first page not visible, including the thumbnail logo at the bottom right – user717452 Aug 04 '22 at 13:34
  • @DonMag I guess the issue then is the content size within the web view being too large to match screen size? – user717452 Aug 04 '22 at 13:42
  • The "thumbnail logo at the bottom right" is not visible in the "wide view" because that's how the pdf is laid out. It's not a matter of the web view being too large for the screen... it's that you're trying to fit a very narrow and tall pdf into a wide/short view. – DonMag Aug 04 '22 at 13:51
  • You may be better off with a `PDFView` instead of using the pdf as the content of a web view. Of course, that won't change the issue with tall/narrow pdf on short/wide view, but you would have more control of it. – DonMag Aug 04 '22 at 13:53
  • @DonMag giving that a try, debugging on it now. Will update end of weekend. Thanks – user717452 Aug 05 '22 at 14:36

0 Answers0