UIView过渡导致崩溃 [英] UIView transition causing crash

查看:110
本文介绍了UIView过渡导致崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

- (IBAction)StartGame:(id)sender
{
    MainGameDisplay *secondPage = [[MainGameDisplay alloc] initWithNibName:nil bundle:nil];

    [self.view addSubview:secondPage.view];
    secondPage.view.frame = CGRectMake(568, 0, 568, 320);//(N = horizontal, N = vertical)
    [UIView animateWithDuration:1.0f
                     animations:^{
                         //actual frame needed with an animation.
                         secondPage.view.frame = CGRectMake(0, 0, 568, 320);
                     }
                     completion:^(BOOL finished) {
                         //ENTER HERE ANYTHING TO RUN AFTER ANIMATION IS COMPLETED:
                         [self presentViewController: secondPage animated:NO completion:NULL];
                         //This will make the next page load correctly after the transition, otherwise you cannot. interact with anything.
                     }];
}

此功能非常适合进入视图。如果没有 [self presentViewController:第二动画页:没有完成:NULL]; ,则无法与新页面进行交互,单击任何按钮都会使其崩溃。

This works perfectly for entering the view. Without [self presentViewController: secondPage animated:NO completion:NULL];, you cannot interact with the new page, any button you click causes it to crash.

如果我返回首页,可以正常进行,那么很好,但是如果我再次单击StartGame,程序将更改视图,然后崩溃。问题在于行 [self.view addSubview:secondPage.view]; ,如果我将其注释掉,程序不会崩溃,但是当它更改视图时它不会崩溃't过渡并立即出现。

If I return back to the first page, doing it normally, it's fine, but if I click StartGame again, the program changes views and then simply crashes. The problem is with the line [self.view addSubview:secondPage.view];, if I comment this out, the program doesn't crash but when it changes views it doesn't transition and instantly appears.

在横向模式下过渡也很滞后/有些浮躁,尽管在肖像上也很完美。

The transition is also pretty laggy/glitchy in landscape mode, perfect in portrait though.

推荐答案

在这里,您要在currentView上添加 secondPage 作为子视图。并再次提出。
我认为它引起一些与内存相关的事情可能是其他事情(如果您在问题中放入一些崩溃日志,这将非常清楚)。但我建议您无需再次显示 secondPage 。这是您在此处进行单行更改的代码。

Here you are Adding secondPage on currentView as aSubview. and Again your presenting it. I think it causing some memory related thing may be some other thing(it would be much clear if you put some crash log here in your question). But i'll suggest you no need to present secondPage Again .Here is your Code i made Single Line Change here .

   - (IBAction)StartGame:(id)sender
      {
      MainGameDisplay *secondPage = [[MainGameDisplay alloc] initWithNibName:nil bundle:nil];



    [self.view addSubview:secondPage.view];
    secondPage.view.frame = CGRectMake(568, 0, 568, 320);//(N = horizontal, N = vertical)
    [UIView animateWithDuration:1.0f
                 animations:^{
                     //actual frame needed with an animation.
                     secondPage.view.frame = CGRectMake(0, 0, 568, 320);
                 }
                 completion:^(BOOL finished) {

                     //ENTER HERE ANYTHING TO RUN AFTER ANIMATION IS COMPLETED:

您应该在sinlge下方发表评论,因为您已经将secondPage添加为currentView上的子视图。因此,无需再次显示它。

                   //  [self presentViewController: secondPage animated:NO completion:NULL];
                     //This will make the next page load correctly after the transition, otherwise you cannot. interact with anything.
                 }];

}

编辑:适用于风景模式您应在设置框架 secondPage 视图时更改坐标。我认为在这里您正在为4英寸设备创建此视图。
在这里,您可以通过设置一些检查来做到这一点

For Landscape Mode you should change coordinate while you are setting the frame secondPage view . i think here you are creating this view for 4 inch Devices. here you can do this by setting some checks as this

   if(checkIfDeviceIsInlandscae)
    {
       secondPage.view.frame = CGRectMake(568, 0, 568, 320);

    } 

   else 
    {
      secondPage.view.frame = CGRectMake(320, 0, 320, 568);
    }

动画内部像我在拖线上方一样,根据方向更改框。

Inside the animation block change the frame according to the orientation, as i did above tow line.

这篇关于UIView过渡导致崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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