Popor Background Color Color Odd Behavior

So, in my application, I have a popover control with a built-in navigation control. In different parts of the navigation stack, I want the popover to be in different colors depending on where the user is located. A strange thing sometimes sets the background color of a popover makes this awful looking box around it, sometimes it doesn’t. It looks like this:

enter image description here

This is the look I'm trying to get:

enter image description here

It seems that if I changed the background color before displaying the popover, it seems to work correctly and translate correctly, but if I did not set the color of the popover before displaying it, change it after it is shown that it has a window effect, I also I noticed other cases when this happens by accident, but I can’t explain what causes it (my real application is much more complicated than this demo). Here is the relevant code:

- (IBAction)buttonPressed:(id)sender {
    UIViewController *vc = [[UIViewController alloc] init];
    UIButton *b = [[UIButton alloc] init];
    [b addTarget:self action:@selector(innerButtonPressed) forControlEvents:UIControlEventTouchUpInside];
    [b setTitle:@"Button" forState:UIControlStateNormal];
    [b setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [b setFrame:CGRectMake(0,0,100,100)];
    [vc.view addSubview:b];
    _innerNav = [[UINavigationController alloc] initWithRootViewController:vc];
    _popOver = [[UIPopoverController alloc] initWithContentViewController:_innerNav];

    //If this line is here, everything works fine
    _popOver.backgroundColor = [UIColor yellowColor];

    [_popOver presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

    //If this line is here (and the above line is commented out), the transition will look wrong
    //_popOver.backgroundColor = [UIColor yellowColor];
}

-(void)innerButtonPressed {
    _controller = [[UIViewController alloc] init];
    UIButton *b = [[UIButton alloc] init];
    [b addTarget:self action:@selector(test) forControlEvents:UIControlEventTouchUpInside];
    [b setTitle:@"Make Purple" forState:UIControlStateNormal];
    [b setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [b setFrame:CGRectMake(0,0,200,200)];
    [_controller.view addSubview:b];
    [_popOver setBackgroundColor:[UIColor orangeColor]];
    [_innerNav pushViewController:_controller animated:YES];
}

-(void)test{
    _popOver.backgroundColor = [UIColor purpleColor];
}

Any idea what is causing this problem? And what are the steps to safely update the popover background color without even getting into this state? I have a complete project demonstrating the problem, I thought that you can attach the projects to the questions, but apparently you cannot. If someone wants this, I can possibly post it somewhere.

+4
2

, Apple "Popover Controllers in iOS" , Apple, , , :

  • UIPopoverController , backgroundColor. , , UIPopoverController backgroundColor nil , , backgroundColor .
  • - ( e.x. popoverContentSize) , (, ).

: < <21 > UIPopoverController, . , UIPopoverController , ( : ). , apple.

, .

+5

UIPopoverController . , popoverPresentationController. backgroundColor UIPopoverController . popover backgroundColor, , , . , , - :

contentViewController.modalPresentationStyle = UIModalPresentationPopover;
[[self presentViewController:contentViewController animated:YES completion:^{
    // completion code
}];
contentViewController.popoverPresentationController.backgroundColor = [UIColor orangeColor];

, , , , poporPresentationController backgroundColor. , , popover :

[self dismissViewControllerAnimated:NO completion:^{

    contentViewController.modalPresentationStyle = UIModalPresentationPopover;

    [[self presentViewController:contentViewController animated:NO completion:^{
        // completion code
    }];
    contentViewController.popoverPresentationController.backgroundColor = [UIColor purpleColor];

}];
+1

Source: https://habr.com/ru/post/1540276/


All Articles