私の didFinishLaunchingWithOptions メソッドで、GLKView と UIButton をサブビューとして作成します。私のコード:
EAGLContext *context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
[EAGLContext setCurrentContext:context];
view = [[GLKView alloc] initWithFrame:[[UIScreen mainScreen] bounds] context:context];
view.delegate = self;
btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setFrame:CGRectMake(5, 50, 200, 50)];
[btn setTitle:@"Run animation" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(buttonClickHandler:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:btn];
controller = [[GLKViewController alloc] init];
controller.delegate = self;
controller.view = view;
tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapHandler:shouldReceiveTouch:)];
tapRecognizer.delegate = self;
[view addGestureRecognizer:tapRecognizer];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = glController;
[self.window makeKeyAndVisible];
view
、controller
、私のクラスbtn
のメンバー変数です。AppDelegate
tapHandler:shouldReceiveTouch:
ボタンのタップを処理したくないのでセレクターを使用するので、これを行います:
- (BOOL) tapHandler:(UIGestureRecognizer *)recognizer shouldReceiveTouch:(UITouch *)touch
{
if ([touch.view isKindOfClass:[UIButton class]])
return NO;
else
{
// some logic ...
return YES;
}
}
問題は、取得した touch.view プロパティを読み込もうとしたときですEXC_BAD_ACCESS
。その理由と回避方法を教えてください。