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];
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];
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;
[v addSubview:showxib];
[v addSubview:showmodal];
}
- (void)showxibTapped
{
[NOZPlayAgainView presentOnView:self.view inRect:CGRectMake(20, 200, 280, 160) withDelegate:self];
}
- (void)showmodalTapped
{
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
Nihat source
share