iOS presentViewController launches half-screen transparent UIViewController

iOS presentViewController launches half-screen transparent UIViewController

No nonsense, just go to the code

1. How to open the parent page

/**
 * page open configuration
 *
 *  @param sender <#sender description#>
 */
- (IBAction)shwoViewAction:(id)sender {
    
    TTViewController *tView = [[TTViewController alloc] init];
    //Set the mode display style
    [tView setModalPresentationStyle:UIModalPresentationOverCurrentContext];
    // Required configuration
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    self.providesPresentationContextTransitionStyle = YES;
    self.definesPresentationContext = YES;
    [self presentViewController:tView animated:YES completion:nil];
}

 2. Subpage rewrite viewWillLayoutSubviews, set position width and height

#define DeviceHeight [[UIScreen mainScreen] bounds].size.height
#define DeviceWidth [[UIScreen mainScreen] bounds].size.width

/**
 * Set the position width and height
 */
- (void)viewWillLayoutSubviews {
  
    self.view.frame = CGRectMake(self.view.frame.origin.x, DeviceHeight / 2, DeviceWidth, DeviceHeight / 2);
    //self.view.backgroundColor = [UIColor clearColor];
    //self.view.backgroundColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:0.868f];
}

 Finish work.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326589662&siteId=291194637
Recommended