错误:UIView 的窗口不等于另一个视图的窗口 [英] Error: UIView's window is not equal to another view's window

查看:18
本文介绍了错误:UIView 的窗口不等于另一个视图的窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个学习 swift 的初学者程序员.第一次在这里发帖.

额外的信息,但可能是不必要的
在我创建的这个应用程序中,用户在主视图控制器上选择一个图像并将其传递给第二个视图控制器.在那里图像被分解成碎片,这些碎片被放置在单独的 UIImageViews 中.目标是通过交换图像将它们按正确的顺序排列.

一切正常,在模拟器中运行正常.但是,我正在尝试添加基本动画(移动 UIImageViews),但它们没有执行.我知道我有正确的动画语法,因为我在另一个项目中测试了代码.

主要问题
当我从主视图控制器导航到第二个视图控制器时,控制台中立即出现错误.这是它所说的:

2014-09-04 17:51:33.489 TileGame[79951:95150647] UIView:0x7f7fe9c84600;框架 = (0 0; 320 568);自动调整大小 = W+H;layer = CALayer: 0x7f7fe9c848d0>> 的窗口不等于 TileGame.GameScreen: 0x7f7fe9dc6bc0> 的视图窗口!

我不明白这是什么意思,但除了妨碍动画外,它似乎没有引起任何问题.有什么想法吗??

看起来这个人有类似的错误消息,但可能比我的应用程序更复杂.presentViewController:animated:completion: 后模态视图控制器 UI 无响应:>

这是我在 GitHub 上的整个项目:https://github.com/pakalewis/Parker-Lewis-CF/tree/master/TileGame

谢谢

解决方案

您似乎对 iOS 编程范式有一些根本性的误解.您的按钮上附加了 segue,但您也可以在代码中调用 performSegue.当您将转场附加到控件时,您不需要任何代码(也不应该有任何代码)来执行转场.除了展开转场之外,您也不应该使用转场返回到先前的视图控制器;您并没有真正返回,而是创建了一个您认为要返回的控制器的新实例.这将导致控制器的建立(因为不会释放任何控制器),直到您的应用程序内存不足为止.

因此,您应该从 MainScreen 中删除 letPlayButton: 函数,并在情节提要中删除它(您只需要附加到该按钮的 segue).

删除您要从 GameScreen 到 MainScreen 的转场,并将 backToMainScreen 中的代码更改为此,

@IBAction func backToMainScreen(sender: AnyObject) {self.dismissViewControllerAnimated(true, 完成: nil)}

I am a beginner programmer learning swift. First post here.

Extra info but maybe unnecessary
In this app I created, the user chooses an image on the main View controller and passes it to the second view controller. There the image is broken up into pieces and those pieces are placed in separate UIImageViews. The objective is to put them in the right order by swapping images.

Everything is working fine and it runs ok in the simulator. However, I am trying to add basic animations (moving the UIImageViews) but they are not performing. I know I have the correct syntax for the animation because I tested the code in another project.

Main question
When I navigate from my main view controller to second view controller, an error immediately appears in the console. Here's what it says:

2014-09-04 17:51:33.489 TileGame[79951:95150647] UIView: 0x7f7fe9c84600; frame = (0 0; 320 568); autoresize = W+H; layer = CALayer: 0x7f7fe9c848d0>>'s window is not equal to TileGame.GameScreen: 0x7f7fe9dc6bc0>'s view's window!

I can't figure out what it means but it does not seem to be causing any problems except for impeding the animation. Any ideas??

Looks like this person had a similar error message but maybe more complicated than my app. Modal viewcontroller UI not responsive after presentViewController:animated:completion:

Here's my whole project on GitHub: https://github.com/pakalewis/Parker-Lewis-CF/tree/master/TileGame

Thanks

解决方案

You seem to have some fundamental misunderstandings of iOS programming paradigms. You have segues attached to your buttons, but you also then call performSegue in code. When you have a segue attached to a control, you don't need any code (and shouldn't have any) to cause the segue to execute. You also shouldn't go back to a previous view controller with a segue, other than an unwind segue; you're not really going back, you're creating a new instance of the controller you think you're going back to. This will cause a build up of controllers (as none will be deallocated) until your app runs out of memory.

So, you should delete the function, letsPlayButton: from MainScreen, and also get rid of it in the storyboard (the segue attached to that button is all you need).

Delete the segue you have going "back" from GameScreen to MainScreen, and change the code in backToMainScreen to this,

@IBAction func backToMainScreen(sender: AnyObject) {
        self.dismissViewControllerAnimated(true, completion: nil)
    }

这篇关于错误:UIView 的窗口不等于另一个视图的窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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