【发布时间】:2016-09-03 17:48:34
【问题描述】:
(touchesBegan not called in a UIView subclass) 来自这个主题的一个扩展。
多年后,我遇到了与上述链接讨论类似的问题,试图将 2009 年的工作(已发布)应用程序升级到最新的 iOS 9.3。我必须添加一个 UIViewController 以防止崩溃并让应用程序加载到模拟器中(XCODE MAC 最新,iPhone6)。重复调用 drawView 例程以按预期刷新屏幕,屏幕上的内容按设计进行动画处理。但是没有点击。 touchesBegan/Ended 永远不会被调用。我可以开始加载代码,但想知道是否立即想到任何事情,因为似乎每个人都有这个问题,或者类似的问题,在某些时候,它通常是一个非常简单的修复。谢谢。
更新:这可能是额外的 uiViewController 与 uiView 混淆,但这是这些 APP 版本之间的添加,它是必需的,不再自动生成。
尝试将 uiView 设置为 firstResponder:
- (id)initWithCoder:(NSCoder*)coder {
if ((self = [super initWithCoder:coder])) {
[self setUserInteractionEnabled:YES];
[self setMultipleTouchEnabled:YES];
[self becomeFirstResponder];
这些是 uiView 的 (glView) touch'ers:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { }
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { }
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
int page; [self adjustPage:&page with:0];
... }
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
int page; [self adjustPage:&page with:0];
... }
这是我的看法@interface EAGLView : UIView <UIAccelerometerDelegate> {。并将这个 viewController 添加到委托中,使其在加载时不会崩溃。
@implementation OpenGLESAppDelegate
@synthesize window;
@synthesize glView;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIViewController* vc = [[UIViewController alloc]initWithNibName:nil bundle:nil];
self.window.rootViewController = vc;
glView.animationInterval = AHZ;
[glView startAnimation];
return YES;
}
没有编译或运行时错误。
【问题讨论】:
-
在真机上能正常工作吗?
-
很遗憾,最早可以配置XCODE的手机是iPhone4s,我的是iPhone4。所以它不会识别它。是模拟器还是半身像。
标签: ios objective-c simulator touchesbegan