Animate popoverContentsize when pushing navigation view controller in popover on iPad

后端 未结 3 1439

How do I get my UIPopoverController to animate its size when its contained UINavigationController pushes a new controller?

I have a UIPopover being display

3条回答
  •  醉酒成梦
    2021-02-07 12:02

    Try to do the following for all UITableViewController, I tried it and it works for me!

    - (void)setSize:(BOOL)fake
    {
        CGSize view_size;
        int sections_height, rows_height;
    
        //if you dynamically change the number of visible rows
        //for example overriding numberOfRowsInSection:section
        //this can help you to evaluate the correct popover height
        int sections = [self.tableView numberOfSections];
        int rows = 0;
        for(int i = 0; i < sections; i++){
            rows += [self.tableView numberOfRowsInSection:i];
        }
        sections_height = sections * 30 /*section height*/;
        rows_height = rows * 44 /*row height*/;
    
        view_size = CGSizeMake(320 /*fixed width*/, sections_height + rows_height);
    
        if(fake){
            view_size.width -= 1;
            view_size.height -= 1;
        }
    
        [self setContentSizeForViewInPopover:view_size];
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        //...    
        [self setSize:FALSE];
    }
    
    - (void)viewWillAppear:(BOOL)animated
    {
        [super viewWillAppear:animated];
        [self setSize:TRUE];
    }
    
    - (void)viewDidAppear:(BOOL)animated
    {
        [self setSize:FALSE];
        [super viewDidAppear:animated];
    }
    

提交回复
热议问题