2

我有以下cameraOverlayView工作在一定程度上。调用时UIImagePickerController,标准控件不显示,“拍照” 按钮和logo.jpg显示为ObViewControllerCameraOverlay中所述。该按钮的功能是按下时变为蓝色,但我的问题是它没有调用该操作(NSLog 仅用于测试目的)。谁能看到我可能做错了什么?

@implementation ObViewControllerCameraOverlay

- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame])
{
    UIImage *logo = [UIImage imageNamed:@"logo.jpg"];
    UIImageView *logoView = [[UIImageView alloc] initWithImage:logo];
    logoView.frame = CGRectMake(0, 0, 240, 50);
    [self addSubview:logoView];

    UIButton *takePhotoButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [takePhotoButton setTitle:@"Take photo" forState:UIControlStateNormal];
    takePhotoButton.frame = CGRectMake(0, 330, 320, 40);
    [self addSubview:takePhotoButton];
}
return self;
}

- (IBAction)takePhotoButton:(id)sender
{
NSLog(@"test");
}
4

1 回答 1

2

看起来你没有告诉你的按钮在takePhotoButton:被点击时调用。尝试添加

[takePhotoButton addTarget:self action:@selector(takePhotoButton:) forControlEvents:UIControlEventTouchUpInside];

在您创建按钮后initWithFrame:

于 2013-12-16T01:50:59.527 回答