Friday, January 27, 2023
HomeiOS Developmentios - External Display View Bounds to Match TV Resolution

ios – 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];
        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.


Source link



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments