gpt4 book ai didi

IOS setUserInteractionEnabled 不起作用

转载 作者:行者123 更新时间:2023-12-01 16:47:38 25 4
gpt4 key购买 nike

我有一个名为 SplashViewController 的 UIViewController 实例。我将它添加到 AppDelegate 的主窗口中,如下所示:

splashViewController = [[SplashViewController alloc]initWithNibName:@"SplashScreen" bundle:[NSBundle mainBundle]];
splashViewController.view.frame = [UIScreen mainScreen].bounds;
[self.window setBackgroundColor:[UIColor blackColor]];
self.window.frame=[UIScreen mainScreen].bounds;
window.rootViewController = splashViewController;
[window makeKeyAndVisible];

我必须在 SplashViewController 中处理触摸事件,并且我需要在程序中将 userInteractionEnabled YES 和 NO 设置为。出于某种原因,我下面的代码无效
[self.view setUserInteractionEnabled:NO]; // YES also have no effect

无论我在上面设置 YES 还是 NO,总是触发我的 touchesBegan 函数。 SplashViewController 有一个带有图像和简单动画的 ImageView 。

我还能在哪里寻找为什么 userInteraction 没有按照我想要的方式行事?我尝试更改 Storyboard 中设置的值,但没有帮助(无论如何程序设置应该覆盖 Storyboard 设置,我猜)。

请提供任何帮助/指针...在此先感谢

最佳答案

尝试设置:

self.view.userInteractionEnabled = YES;

在 SplashViewController 对象的“ viewWillAppear:”方法中。

另外,您是否将“ splashViewController”保存为应用程序委托(delegate)中的实例变量?您在 AppDelegate 的 .h 或 .m 文件中的何处声明“ SplashViewController * splashViewController;”?如果它没有在您的应用程序委托(delegate)中设置为 ivar,则它可能会在您添加后立即发布。

关于IOS setUserInteractionEnabled 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18679885/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com