【问题标题】:IOS setUserInteractionEnabled not workingIOS setUserInteractionEnabled 不起作用
【发布时间】:2013-09-08 02:43:48
【问题描述】:

我有一个名为 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 有一个带有图像和简单动画的图像视图。

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

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

【问题讨论】:

    标签: ios objective-c touch


    【解决方案1】:

    尝试设置:

    self.view.userInteractionEnabled = YES;
    

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

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

    【讨论】:

    • 您好,感谢您的指出。我在这里更正了我的语法。我使用的是 [self.view setUserInteractionEnabled:NO],它是一个有效的语法。我认为它应该和 self.view.userInteractionEnabled=NO; 一样也试过这个,但没有解决我的问题。谢谢
    猜你喜欢
    • 2013-02-14
    • 1970-01-01
    • 2012-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多