swift – Getting black screen when a viewcontroller is dismissed ios 16+


I have a custom UITabBarController written in Objective-C and It’s rootViewController of MainWindow. I have 5 Tabs all with UINavigationControllers. Now From UIViewController A I’m pushing UIViewController B. From B I’m presenting a UIViewController C from tabbarController which is a property in my App Delegate. Now If I dismiss C I’m getting a black screen. I’ve tested the issue in iPhone 14 Pro ioS 17 Simulator and iPhone 8 iOS 16+. If I use self(B) to present C it works fine. However earlier everything was working fine. Anyone have any idea what could be the issue? Also I’m getting below warnings if I try to present any UINavigationController from swift class.

BUG IN CLIENT OF UIKIT: Setting UIDevice.orientation is not supported. Please use UIWindowScene.requestGeometryUpdate(_:)
[Presentation] Attempt to present <UINavigationController: 0x154058200> on <LeveyTabBarController: 0x156518490> (from <LeveyTabBarController: 0x156518490>) whose view is not in the window hierarchy.

Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <UITableView: 0x11284ce00; frame = (0 0; 0 0); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x282235200>; backgroundColor = UIExtendedSRGBColorSpace 0.145098 0.168627 0.203922 1; layer = <CALayer: 0x282dea380>; contentOffset: {0, 0}; contentSize: {0, 233}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <DroneNation.BNCommentsViewController: 0x112846400>>

`- (void)showCropperWithImage:(UIImage*)image inViewController:(UIViewController*)controller {

// NSAssert(image == nil, @”Image must not be nil”);
// NSAssert(controller == nil, @”Controller must not be nil”);

TOCropViewController *cropController = [[TOCropViewController alloc] initWithCroppingStyle:TOCropViewCroppingStyleDefault image:image];
cropController.delegate = self;
cropController.modalPresentationStyle = UIModalPresentationFullScreen;
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:cropController];
navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
[controller presentViewController:navigationController animated:YES completion:NULL];

}

  • (void)cropViewController:(TOCropViewController *)cropViewController didCropToImage:(UIImage )image withRect:(CGRect)cropRect angle:(NSInteger)angle
    {
    AppDelegate
    delegate = [AppDelegate applicationDelegate];
    __weak typeof(self) weakSelf = self;
    [UtilsMethods setPortraitOrientation];
    [cropViewController dismissViewControllerAnimated:YES completion:^{
    __strong typeof(weakSelf) strongSelf = weakSelf;
    if (strongSelf) {
    if (self.delegate && [self.delegate respondsToSelector:@selector(dnImageCropperDidFinishedCroppingImage:)]) {
    [self.delegate dnImageCropperDidFinishedCroppingImage:image];
    }
    }
    }];
    }

  • (void)cropViewController:(nonnull TOCropViewController *)cropViewController
    didFinishCancelled:(BOOL)cancelled {
    [UtilsMethods setPortraitOrientation];
    [cropViewController dismissViewControllerAnimated:YES completion:^{

      if (self.delegate && [self.delegate respondsToSelector:@selector(dnImageCropperDidCancelled)]) {
          [self.delegate dnImageCropperDidCancelled];
      }
    

    }];
    }`

Here is my UTIL class function
`+ (void)setPortraitOrientation {
if (@available(iOS 13, *)){
[[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@”orientation”];

    [UINavigationController attemptRotationToDeviceOrientation];
    
    
}
if (@available(iOS 11.0, *)) {
    [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}

}`

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img