将UIButton动作事件放在cameraview上时,它不起作用

时间:2015-01-30 09:14:09

标签: ios iphone ipad uibutton zxing

我已将zxing条形码扫描集成到我的应用程序中。一切都很好,但是我在zxing.But提供的OverlayView.m文件中添加了自定义取消按钮,事件操作未执行。我不知道是什么原因。它适用于iPhone,但它不适用于Ipad。

这是我使用

的代码
- (id) initWithFrame:(CGRect)theFrame cancelEnabled:(BOOL)isCancelEnabled oneDMode:(BOOL)isOneDModeEnabled {
if( self == [super initWithFrame:theFrame] ) {

    self.oneDMode = isOneDModeEnabled;
    //CGFloat rectSize = self.frame.size.width - kPadding * 2;
    //CGFloat rectSize2 = self.frame.size.height - kPadding * 2;
    // it effects cropping
    // 1st param effect the border line of rect and second param effects left vertical of rect 3rd param effects width and 4th param effects the height..




    self.backgroundColor = [UIColor clearColor];
    //self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self                                                     selector:@selector(mytimer)                                                    userInfo:Nil repeats:YES];

    // logo ..
    UILabel *logo = [[UILabel alloc] init];

    UIImageView *img = [[UIImageView alloc]
                        initWithImage:[UIImage imageNamed:@"Technolabs.PNG"]];
    [logo addSubview:img];
    [img release];
    logo.backgroundColor = [UIColor clearColor];

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
        cropRect = CGRectMake(kPadding * 4, kPadding * 4, self.frame.size.width - (kPadding*20) , self.frame.size.height - (kPadding * 6));

        [logo setFrame:CGRectMake(50, 425, 218, 53)];
    }
    else{
        cropRect = CGRectMake(kPadding * 2, kPadding * 3, self.frame.size.width - (kPadding*4) , self.frame.size.height - (kPadding * 6));
        [self.cancelButton setFrame:CGRectMake(260, 40, 50, 50)];
        [logo setFrame:CGRectMake(10, 225, 80, 203)];
    }

    [self addSubview:logo];

    if (isCancelEnabled) {
        //UIButton *butt = [UIButton buttonWithType:UIButtonTypeRoundedRect];

        cancelButton = [[UIButton alloc] init];
        //[cancelButton setTitle:@"Cancel" forState:UIControlStateNormal];
        if (oneDMode) {
            UIImage *img = [UIImage imageNamed:@"closebutton.png"];
            [cancelButton setImage:img forState:UIControlStateNormal];
            //[img release];
            //[cancelButton setTransform:CGAffineTransformMakeRotation(M_PI/2)];

        }
        [cancelButton setFrame:CGRectMake(660, 40, 50, 50)];
        cancelButton.backgroundColor = [UIColor clearColor];
        [cancelButton addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpInside];

        //[self addSubview:imageView];
    }

    cancelButton.userInteractionEnabled = YES;
    cancelButton.enabled = YES;

    [self addSubview:cancelButton];

    UIButton *cancel_Button = [[UIButton alloc] init];
    UIImage *img1 = [UIImage imageNamed:@"closes.png"];
    [cancel_Button setImage:img1 forState:UIControlStateNormal];
    cancel_Button.frame = CGRectMake(600.0, 40, 50, 50);
    cancel_Button.hidden = NO;
    cancel_Button.backgroundColor = [UIColor clearColor];
    [cancel_Button addTarget:self action:@selector(cancel:) forControlEvents:UIControlEventTouchUpOutside];
    //[self addSubview:cancel_Button];
}

return self;
}

请任何人都可以帮我解决这个问题。谢谢你提前我已经尝试了所有可能的事情来实现它但行动没有发生且方法根本没有调用。

0 个答案:

没有答案