ios - 我的 iOS 7 相机覆盖层有什么问题?

标签 ios objective-c camera-overlay

每当我在设备上运行应用程序并选择拍照时,它就会在没有警告的情况下崩溃,有人可以告诉我叠加层出了什么问题吗?

CameraOverlay.h 除了使 UIView 成为父类(super class)之外不包含任何内容。

CameraOverlay.m

@implementation CameraOverlay

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.opaque = NO;
        self.backgroundColor = [UIColor clearColor];

        // load an image to show in the overlay
        UIImage *constraints = [UIImage imageNamed:@"camera_overlay"];
        UIImageView *constraintView = [[UIImageView alloc]initWithImage:constraints];
        constraintView.frame = CGRectMake(30, 100, 260, 200);
        [self addSubview:constraintView];

    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end

viewController.m

- (IBAction)scanButton:(UIButton *)sender
{
    CGRect screenRect = [[UIScreen mainScreen]bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;

    CameraOverlay *overlay = [[CameraOverlay alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];

    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.cameraOverlayView = overlay;
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    [self presentViewController:picker animated:YES completion:NULL];
}

最佳答案

我发现出了什么问题,我在将源设置到相机之前设置了相机的叠加层。

ViewController 中的更新代码

- (IBAction)scanButton:(UIButton *)sender
{
    CGRect screenRect = [[UIScreen mainScreen]bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;

    CameraOverlay *overlay = [[CameraOverlay alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];

    UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraOverlayView = overlay;
    picker.delegate = self;
    picker.allowsEditing = YES;


    [self presentViewController:picker animated:YES completion:NULL];
}

关于ios - 我的 iOS 7 相机覆盖层有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21895745/

相关文章:

objective-c - 如何检测退格键何时被长按?

ios - 如何创建垂直进度条 - IOS - Swift

iphone - UITextView 没有成为 iOS 7 中的第一响应者

objective-c - 在与主类分开的 .m 文件中实现 objc 协议(protocol)方法?

android - 在自定义 Camera2 API 上显示矩形边界框(覆盖),以便仅捕获框内的图像

iOS - 在相机上定位自定义叠加层(垂直对齐)。顶部黑条的大小

ios - 是否可以在 SwiftUI 中对某个路径上的 View 进行动画处理

ios - 从用户手机 Objective C 分享视频

objective-c - 为 subview 应用头文件和实现文件

ios - CameraOverlayView 上的按钮不起作用