使用Storyboard在UIImagePickerController上创建Overlay View

时间:2015-01-23 04:00:31

标签: ios objective-c uiview storyboard uiimagepickercontroller

我正在尝试在UIImagePickerController相机预览屏幕上创建自定义叠加层。我不确定如何使用故事板使用XCode 6。我正在使用Objective-C。

我已经预览了相机。我在故事板中创建了一个UIView,我使用了:picker.cameraOverlayView = overlay;

创建叠加视图。但是如何将我的故事板中的UIView连接到我的代码中的叠加层?在我看来,UIView总是出现在UIImagePickerController的相机预览下面。如何将自定义叠加层放在UIImagePickerController视图的“顶部”?

由于

1 个答案:

答案 0 :(得分:1)

我通过使用图像png实现了这一点并在顶部显示...创建一个类“OverlayView”...

·H

#import <UIKit/UIKit.h>

@interface OverlayView : UIView

@end  

的.m

#import "OverlayView.h"

@implementation OverlayView


- (id)initWithFrame:(CGRect)frame {
  if (self = [super initWithFrame:frame]) {
    //clear the background color of the overlay
    self.opaque = NO;
    self.backgroundColor = [UIColor clearColor];

    //load an image to show in the overlay

    UIImage *overlayImgae = [UIImage imageNamed:@"overlay.png"];
    UIImageView *overlayImageView = [[UIImageView alloc]
                                 initWithImage:overlayImage];
    overlayImageView.frame = CGRectMake(115, -20, 815, 815);
    [self addSubview:overlayImageView];

    }

    return self;
    }

    @end

根据图像的大小改变CGRectMake ...然后在ViewController中初始化imagePicker做

#import "OverlayView.h"

UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];




OverlayView *overlay = [[OverlayView alloc]
                        initWithFrame:CGRectMake(0, -24.25, SCREEN_WIDTH, SCREEN_HEIGTH)];

imagePicker.cameraOverlayView = overlay;

再次更改CGRectMake数字以适合......