我正在使用 vuforia 增强现实应用程序。我在 EAGLView 中显示一个按钮。但是按钮没有响应点击事件。在检测到 ImageTarget 时,我必须获取叠加层顶部的增强内容的屏幕截图。图像识别覆盖内容后,按钮显示在覆盖顶部。但是在单击按钮时,它没有响应用户事件
EAGLView.h:
Display 3D object:
@interface Object3D : NSObject {
unsigned int numVertices;
const float *vertices;
const float *normals;
const float *texCoords;
unsigned int numIndices;
const unsigned short *indices;
Texture *texture;
}
@interface ImageTargetsEAGLView : UIView <UIGLViewProtocol> {
@private
UIButton *photo;
}
@property (nonatomic) BOOL takePhotoFlag;
EAGLView.mm:
- (id)initWithFrame:(CGRect)frame appSession:(SampleApplicationSession *) app
{
self = [super initWithFrame:frame];
if (self) {
takePhotoFlag = NO;
[self DisplayPhotoButton];
return self;
}
- (void)takePhoto
{
NSLog(@"button pressed");
takePhotoFlag = YES;
}
- (void)DisplayPhotoButton
{
UIImage *closeButtonImage = [UIImage imageNamed:@"button.png"];
// UIImage *closeButtonTappedImage = [UIImage imageNamed:@"button_close_pressed.png"];
CGRect aRect = CGRectMake(20,20,
closeButtonImage.size.width,
closeButtonImage.size.height);
photo = [UIButton buttonWithType:UIButtonTypeCustom];
photo.frame = aRect;
[photo setImage:closeButtonImage forState:UIControlStateNormal];
[photo addTarget:self action:@selector(takePhoto) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:photo];
}
- (BOOL)presentFramebuffer
{
if (takePhotoFlag)
{
[self glToUIImage];
takePhotoFlag = NO;
}
}
显示叠加的代码:
- (void)targetFound:(NSNotification *)notification
{
dispatch_async(dispatch_get_main_queue(), ^{
self.targetOverlayView = [[[NSBundle mainBundle] loadNibNamed:@"targetOverlayView" owner:nil options:nil] objectAtIndex:0];
Book *aBook = [notification object];
[self.targetOverlayView setBook:aBook];
[booksDelegate setLastScannedBook:aBook];
[booksDelegate setOverlayLayer:self.targetOverlayView.layer];
[self.view addSubview:self.targetOverlayView];
}