简体   繁体   English

为什么在Xcode中不同大小的Storyboard中无法使用某些代码?

[英]Why Won't Some Code Work in Different Size Storyboards in Xcode?

I am a low intermediate Xcode programmer. 我是中级Xcode程序员。 if I am not clear in something please bear with me and help me improve with feedback. 如果我不清楚某件事,请忍受并帮助我改善反馈。 Any feedback i am given, I will use to improve this question. 我得到的任何反馈,我都会用来改进这个问题。

I am using Xcode 6 我正在使用Xcode 6

I am currently making an Iphone Game. 我目前正在制作Iphone游戏。 I set it up as a single view application. 我将其设置为单视图应用程序。 My problem is making it work on different Size IPhones. 我的问题是使其可以在不同尺寸的iPhone上使用。 At first, I did not know how to make Xcode pick the screens depending on which Iphone it is being played on, but I managed to make it work. 起初,我不知道如何让Xcode根据正在播放的Iphone来选择屏幕,但是我设法使其工作。 My game is not using Auto Layout, it uses different storyboards in which the view controllers are different depending on the storyboard. 我的游戏没有使用“自动布局”,而是使用了不同的情节提要,其中,根据情节提要的不同,视图控制器也有所不同。 For example: MainIphone6.Storyboard will have Iphone 6 view controllers. 例如:MainIphone6.Storyboard将具有Iphone 6视图控制器。

My game consists of tapping image views (they do have tap gesture recognizers), after they are tapped the image view will pick a random point on the screen and move to it. 我的游戏由点击图像视图(它们具有点击手势识别器)组成,在点击它们后,图像视图将在屏幕上选择一个随机点并将其移至该点。 the point has boundaries which I set so it will not go to places I don't want it to. 该点具有我设定的边界,因此不会到达我不希望的地方。

The first screen I made it work on was Iphone 5. It works perfectly. 我可以在其上运行的第一个屏幕是Iphone5。它可以完美运行。 The second screen I made it work on was Iphone 4, the boundaries for the random positions are a little off do to the fact that it was originally programmed for iPhone 5, but I know how to fix this, that is not the problem. 我在其上运行的第二个屏幕是Iphone 4,其随机位置的边界与最初为iPhone 5编程的事实略有不同,但是我知道如何解决此问题,这不是问题。

The problem is that in my storyboards for Iphone 6 and 6 Plus, when the Image View is tapped, it doesn't move to the random point. 问题在于,在我的Iphone 6和6 Plus故事板中,当轻按“图像视图”时,它不会移动到随机点。 This works on Iphone 5 and 4, but not on 6 and 6 plus. 这适用于Iphone 5和4,但不适用于6和6 plus。

Why doesn't my code work for this Storyboard, but it works on other storyboards, while it is the same code for all? 为什么我的代码不能用于此情节提要,但是却适用于其他情节提要,而所有代码都相同?

Note: I have speculated that it may be related to the linking of view controllers within story boards, because on iPhone 5 and 4 i can link with the modal segue, but in 6 and 6 plus, it says it is deprecated. 注意:我推测这可能与故事板上的视图控制器的链接有关,因为在iPhone 5和4上,我可以与模式选择链接,但在6和6以及更高版本中,它表示已弃用。 I only mention this if it might help... 我只会提及这可能会有所帮助...

Hard to tell from just your description. 仅凭您的描述很难分辨。 Deprecated code will still work so I doubt it is that. 不推荐使用的代码仍然可以使用,所以我怀疑是这样。 Did you try changing you code so that the 6 and 6 plus used the working 5 Storyboard. 您是否尝试过更改代码,以便6和6加上可以使用的5个Storyboard。 If it does the 6 storyboard has a problem. 如果这样做,则6分镜脚本有问题。 In this case, kill the 6 Storyboards, duplicate the 5 Storyboard and modify it. 在这种情况下,杀死6个Storyboard,复制5个Storyboard并对其进行修改。 Sounds like you may have been recreating each Storyboard anyway. 听起来您可能一直在重新创建每个情节提要。 In this situation I select the Storyboard in the Navigator and choose Duplicate from the File menu. 在这种情况下,我在导航器中选择情节提要,然后从“文件”菜单中选择“复制”。 This will save you some work and help guarantee that you do not make a mistake recreating all aspects of the Storyboard. 这将为您节省一些工作,并有助于确保您在重新创建情节提要的所有方面时都不会出错。

Also even if you do not want to use Autolayout, I would still use a single Storyboard and make the calculations in code. 同样,即使您不想使用“自动布局”,我仍然会使用单个Storyboard并在代码中进行计算。

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

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