在SKView上加载Xib视图后,ModalViewController上的滞后/延迟关闭 [英] Lag / Delay on ModalViewController dismiss after loading an xib view over SKView

查看:98
本文介绍了在SKView上加载Xib视图后,ModalViewController上的滞后/延迟关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象这种情况(下面的一些代码):

Imagine this scenario (some code below):

  1. 我在视图控制器上有一个SKView.
  2. 我在skview上加载了一个xib视图(外部.xib文件)(xib视图就像一个小的菜单视图,不能完全覆盖整个屏幕).
  3. 然后,我从SKView的控制器中以模态显示视图控制器
  4. 当我关闭此模态视图控制器时,每秒的关闭都会有延迟(因此,我以模态显示它,关闭,很好,然后我重复,有延迟,然后重复,可以正常工作,然后再做一次,有延迟...等等)
  5. 如果我不使用SKView(如果我只是使用UIView),则不会发生这种延迟.仅当我使用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

推荐答案

它是由xib视图上的自动布局约束引起的.为了得出这个结论,我创建了一个带有子视图的简单视图,并将其添加到SKView中.我上面报告的问题仅在使用自动布局约束放置子视图时发生.我不知道为什么会这样,但这就是原因.

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.

这篇关于在SKView上加载Xib视图后,ModalViewController上的滞后/延迟关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆