Lag / Delay on ModalViewController to fire after loading the xib view via SKView

Imagine this scenario (code below):

  • I have an SKView on a viewcontroller.
  • I load an xib view (external .xib file) on top of the skview (the xib view is like a view of a small menu that does not completely cover the screen).
  • Then I show the view controller using the SKView controller
  • When I reject this modal view controller, there is a lag on every second dismissal (so I show it in different ways, dismiss is fine, then I repeat, there is a delay, then I repeat, it works fine, and then I do it again, there is a delay. .. etc.)
  • If I do not use SKView (if I just used UIView), this delay will not happen. This only happens when using SKView.

What could be the reason for this? Here is the simplified code that creates this problem:

@implementation NOZTestController
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    // button that loads xib view onto the current skview 
    UIButton *showxib = [[UIButton alloc] initWithFrame:CGRectMake(20, 80, 280, 30)];
    [showxib setTitle:@"Add xib view here" forState:UIControlStateNormal];
    [showxib addTarget:self action:@selector(showxibTapped) forControlEvents:UIControlEventTouchUpInside];

    // button that loads a view controller programmatically 
    UIButton *showmodal = [[UIButton alloc] initWithFrame:CGRectMake(20, 120, 280, 30)];
    [showmodal setTitle:@"Show modal" forState:UIControlStateNormal];
    [showmodal addTarget:self action:@selector(showmodalTapped) forControlEvents:UIControlEventTouchUpInside];


    self.view = [[SKView alloc] initWithFrame:self.view.frame];
    SKView *v = (SKView *)self.view;

    //UIView *v = self.view;

    [v addSubview:showxib];
    [v addSubview:showmodal];

}

- (void)showxibTapped
{
    // displays the xib view 
    [NOZPlayAgainView presentOnView:self.view inRect:CGRectMake(20, 200, 280, 160) withDelegate:self];
}

- (void)showmodalTapped
{
    // displays the modal window 
    UIViewController *vc = [[UIViewController alloc] init];

    UIButton *dismiss = [[UIButton alloc] initWithFrame:CGRectMake(40, 40, 240, 40)];
    [dismiss setTitle:@"Dismiss" forState:UIControlStateNormal];    
    [dismiss addTarget:self action:@selector(dismissModal) forControlEvents:UIControlEventTouchUpInside];
    [vc.view addSubview:dismiss];


    [self presentViewController:vc animated:YES completion:nil];
}

- (void)dismissModal
{
    [self.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}

@end
0
source share
1 answer

This is caused by auto-detection restrictions on xib view. To come to this conclusion, I created a simple view with a preview and added it to SKView. The problem I reported above only happened when I used the auto-layout constraints to host the subview. I do not know why this is happening, but this is the reason.

+2
source

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


All Articles