我正在尝试在默认摄像机视图上实现一个按钮,该按钮会在录制后打开照片库。现在我实现了一个显示按钮的自定义覆盖视图类,但UIImagePicker没有呈现或不可见(由多个视图覆盖)。
CameraOverlayView.h
#import <UIKit/UIKit.h>
@interface CameraOverlayView : UIView <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{}
- (UIViewController *)viewController;
- (void) button1:(UIButton *)paramSender;
@end
CameraOverlayView.m
#import "CameraOverlayView.h"
@implementation CameraOverlayView
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
//clear the background color of the overlay
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
//add a simple button to the overview
//with no functionality at the moment
UIButton *button = [UIButton
buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(button1:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Select" forState:UIControlStateNormal];
CGPoint buttonOffset = CGPointMake( ([[UIScreen mainScreen] bounds].size.width - button.frame.size.width) / 2, ([[UIScreen mainScreen] bounds].size.height - button.frame.size.height) / 2);
button.frame = CGRectMake(buttonOffset.x, buttonOffset.y, 400, 50);
[self addSubview:button];
}
return self;
}
- (void) button1:(UIButton *)paramSender{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self.viewController presentViewController:picker animated:YES completion:nil];
//debugging
NSLog(@"sup!");
}
//find the first responder to access the UIViewController
- (UIViewController *)viewController {
if ([self.nextResponder isKindOfClass:UIViewController.class])
return (UIViewController *)self.nextResponder;
else
return nil;
}
请注意,当我运行代码时没有错误,“选择”按钮显示正确。当我点击按钮时,它会显示NSLog消息,但不会打开照片库。有谁知道这里的问题是什么?
谢谢!