简体   繁体   English

故事板ViewController UI故障

[英]Storyboard ViewController UI Glitch

I've got an app that I used Storyboard and autolayout to lay out. 我有一个使用情节提要和自动布局进行布局的应用程序。 I used a UINavigationViewController to programmatically transition between UIViewControllers on button pushes. 我使用UINavigationViewController在按钮按下时以编程方式在UIViewController之间进行了转换。 I used XCode 6 with a minimum iOS version number of 7.1 (tested on iPhone 4s). 我使用的XCode 6的最小iOS版本号为7.1(在iPhone 4s上测试)。

I wanted to write a universal interface that would scale to all screen sizes (iPhone, iPad, etc.). 我想编写一个可以缩放到所有屏幕尺寸(iPhone,iPad等)的通用界面。 In order to do this, I used UIViews that were defined proportionally to screen size to separate the views (please see Figure 1): 为了做到这一点,我使用了与屏幕尺寸成比例定义的UIView来分离视图(请参见图1):

图1
Figure 1 - Screenshot of main page of test application 图1-测试应用程序主页的屏幕截图

In figure 1 as shown above, the red squares are UIViews that are defined proportionally to screen size that are used to "space out" the "real" views (those that are blue and gray). 在上面的图1中,红色方块是与屏幕尺寸成比例定义的UIView,用于“隔开”“真实”视图(蓝色和灰色的视图)。

Unfortunately, I began to notice that when the user transitioned between UIViewControllers, the views in the view controllers would "resize" (views would move a few pixels or resize by a few pixels) just after transition. 不幸的是,我开始注意到,当用户在UIViewControllers之间切换时,视图控制器中的视图将在过渡后立即“调整大小”(视图将移动几个像素或将尺寸调整几个像素)。 This creates the rather irritating experience of the entire interface changing slightly after the user transitions to the appropriate screen. 在用户转换到适当的屏幕后,这会导致整个界面略有变化的令人烦恼的体验。

I culled the project down to a reasonable minimum of code required to produce this resizing effect in hopes that someone could help me out (because I'm at a loss). 我将项目缩减到产生这种调整大小效果所需的合理的最少代码,以希望有人可以帮助我(因为我很茫然)。

Storyboard view hierarchy for 1st view controller: 第一个视图控制器的情节提要视图层次结构: 1st View Controller的视图层次

Constraints for first view controller: 第一视图控制器的约束:
1st View Controller的约束

Setup of second view controller: 第二个视图控制器的设置:
设置第二个视图控制器

Code used to transition from 1st to second controller (push): 用于从第一个控制器过渡到第二个控制器(推动)的代码:

- (IBAction)transitionForward:(UIButton *)sender
{
    UIViewController *controller = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"BackController"];
    [self.navigationController pushViewController:controller animated:YES];
}

Code used to pop from second controller to the first one: 从第二个控制器弹出到第一个控制器的代码:

- (IBAction)transitionBack:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

As stated, the issue is that the interface appears to slightly resize itself/move around right after the view controller loads after a push/pop triggered by the user clicking on a button. 如前所述,问题是在用户单击按钮触发的推入/弹出操作后,视图控制器加载后,界面似乎在略微调整自身大小/移动。 This effect is rather jarring and I would really appreciate any suggestions on how to stop it. 这种影响相当刺耳,我真的很感激任何有关如何停止它的建议。

The simplified project that demonstrates the issue can be found at Github . 可以在Github上找到演示该问题的简化项目。

If there is anything else I can provide, please just ask. 如果我还有其他可以提供的,请问。 Thank you for your time and assistance. 感谢您的时间和协助。


Edit: Upon further investigation, it appears that the viewDidLayoutSubviews method of the view controllers is being called twice on view controller transition (in case that helps anyone diagnose the problem). 编辑:经过进一步调查,似乎在视图控制器转换时两次调用了视图控制器的viewDidLayoutSubviews方法(以防任何人诊断问题)。

Try replacing your push and pop function with this code and leme know your requirements are meet or not. 尝试用此代码替换push和pop函数,然后leme知道您的要求是否满足。

- (IBAction)transitionBack:(UIButton *)sender
{
    CATransition *transition = [CATransition animation];
    transition.duration = 0.45;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
    transition.type = kCATransitionFromLeft;
    [transition setType:kCATransitionPush];
    transition.subtype = kCATransitionFromLeft;
    transition.delegate = self;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];


    [self.navigationController popViewControllerAnimated:NO];
}

- (IBAction)transitionForward:(UIButton *)sender
{

    UIViewController *controller = [self.navigationController.storyboard instantiateViewControllerWithIdentifier:@"BackController"];
    CATransition *transition = [CATransition animation];
    transition.duration = 0.45;
    transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionDefault];
    transition.type = kCATransitionFromRight;
    [transition setType:kCATransitionPush];
    transition.subtype = kCATransitionFromRight;
    transition.delegate = self;
    [self.navigationController.view.layer addAnimation:transition forKey:nil];


    [self.navigationController pushViewController:controller animated:NO];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM