想象一下这种情况(下面的一些代码):
- 我在视图控制器上有一个 SKView。
- 我在 skview 上加载了一个 xib 视图(外部 .xib 文件)(xib 视图是一个类似的小菜单视图,它不会完全覆盖屏幕)。
- 然后,我从 SKView 的控制器模态显示一个视图控制器
- 当我关闭这个模态视图控制器时,每隔一秒就会有一个延迟(所以,我以模态方式显示它,关闭,很好,然后我重复,有延迟,然后重复,工作正常,然后再做一次,有延迟......等等)
- 如果我不使用 SKView(如果我只使用 UIView),则不会发生延迟。仅在我使用 SKView 时才会发生。
可能是什么原因造成的?这是产生此问题的简化代码:
@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