按钮单击事件没有响应

时间:2014-04-07 04:48:01

标签: ios opengl-es uibutton vuforia eaglview

我正在使用vuforia增强版Reality应用。我在EAGLView中显示一个按钮。但该按钮没有响应click事件。我必须获得在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];
}

0 个答案:

没有答案