Animate popoverContentsize when pushing navigation view controller in popover on iPad

后端 未结 3 1441

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 11:57

    I think you were close if you tried keeping a reference to the popoverController and used setPopoverContentSize:animated:

    What works for me is this combination of setPopoverContentSize:animated: AND contentSizeForViewInPopover in that specific order, for each controller your put on the stack:

    -(void)viewDidAppear:(BOOL)animated
    {
        [self.popoverController setPopoverContentSize:whateverSize animated:true];
        self.contentSizeForViewInPopover = whateverSize;
        [super viewDidAppear:animated];
    }
    

    In this case, self.popoverController is a reference I keep in each controllers that is pushed on the stack, it would probably be cleaner to use a singleton variable for that.

    0 讨论(0)
  • 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];
    }
    
    0 讨论(0)
  • 2021-02-07 12:09

    If animation is what you seek, you can try the following piece of code. Honestly speaking, I have no experience in iPad development, but I use it to animate frame and alpha changes in almost all my projects. The Parameters are simple, you have, in order, the duration over which animation occurs, time delay, animation options, the block where you specify the changes in view, and another block object where you specify the aftermath.

    [UIView animateWithDuration:1.0
                          delay:0.0
                        options: UIViewAnimationCurveEaseOut
                     animations:^{
                   self.contentSizeForViewInPopover = CGSizeMake(320, self.items.count * 44);
                     }
                     completion:^(BOOL finished){
                    //Insert what you need to do after the animation is over
                     }];
    

    You can try putting it in the -(void)viewDidAppear:(BOOL)animated

    Try it out and let me know if it works.

    0 讨论(0)
提交回复
热议问题