Question

Imagine this scenario (some code below):

  1. I have an SKView on a viewcontroller.
  2. I load an xib view (external .xib file) over skview (xib view is a like small menu view that does not cover screen in full).
  3. Then, I show a view controller modally from SKView's controller
  4. When I dismiss this modal view controller, there is a lag on every second dismissal (so, i show it modally, dismiss, it is fine, then i repeat, there is delay, then repeat, works fine, then do again, there is delay ... and so on)
  5. If I do not use SKView (if i just used UIView), that delay does not happen. It only happens when I use SKView.

What may be causing that? Here is simplified code that produces 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
Was it helpful?

Solution

It is caused by autolayout constraints on the xib view. To arrive to that conclusion, I created a simple view with a subview and added it to SKView. The problem I reported above happened only when I used auto layout constraints to place the subview. I don't know why this is happening but that is the reason for it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top