iPhone Modal View Smaller that the screen

后端 未结 5 1054
一生所求
一生所求 2021-01-31 06:23

I\'m trying to do something that shouldn\'t be that complicated, but I can\'t figure it out. I have a UIViewController displaying a UITableView. I want to present a context menu

5条回答
  •  庸人自扰
    2021-01-31 06:50

    What I did was create a UIViewController on top of my UINavigation controller in my app delegate and made it a property of a singleton object for convenience:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    
    //--- create root navigation controller
    self.window.rootViewController = self.navigationController;
    
    //--- create view controller for popups:
    popupViewController = [[BaseViewController alloc] init];
    popupViewController.view.backgroundColor = [UIColor clearColor];
    popupViewController.view.hidden = true; //for rendering optimisation
    [self.window addSubview:popupViewController.view];
    [AppState sharedInstance].popupViewController = self.popupViewController;
    
    //--- make all visible:
    [self.window makeKeyAndVisible];
    
    return YES;
    

    }

    At any point in my app, I can then call e.g.

    MyViewController * myVC = [[UIViewController alloc] init];
    //... set up viewcontroller and its view...
    // add the view of the created view controller to the popup view:
    [AppState sharedInstance].popupViewController.view.hidden = false;
    [[AppState sharedInstance].popupViewController.view addSubview:myVC.view];
    

    The BaseViewController used on the top just inherits from UIViewController and sets up a full-screen view:

    //----- in BaseViewController implementation
    - (void)loadView {
       //------- create root view:
       CGRect frame = [[AppState sharedInstance] getScreenFrame]; 
       rootView = [[VCView alloc] initWithFrame:frame];
       rootView.backgroundColor = [UIColor whiteColor];
       self.view = rootView;
    }
    

提交回复
热议问题