如何在IOS中的原生相机视图上叠加文本框

时间:2016-01-04 14:03:26

标签: ios objective-c text camera native

在执行构建时遇到问题我正试图完成。

我有构建1和构建2完成。

构建1 - 一个简单的空白屏幕,带有两个带对齐约束的文本框

构建2 - 运行应用程序时,它会调用IOS设备的本机后置摄像头。

我的第三个版本是将这两个以前的版本组合为一个版本,其中本机相机显示实时视频源和覆盖层是两个带有对齐约束的文本框。

我不确定如何将两位代码放在一起。

我目前拥有的代码:

构建1 - .h文件

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (strong, nonatomic) IBOutlet UIView *TestTextBox;

@property (weak, nonatomic) IBOutlet UITextView *TestTetBox2;

@end

构建1 - .m文件

#import "ViewController.h"

@interface ViewController ()

@end



@implementation ViewController

@synthesize TestTextBox;

@synthesize TestTetBox2;


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

构建2 - .h文件

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate>

@property (strong, nonatomic) IBOutlet UIImageView *imageView;


@end

构建2 - .m文件

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];

    if (self.imageView.image == nil) {
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
        imagePickerController.delegate = self;
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera; //Defualts to Native Camera View
        imagePickerController.showsCameraControls = NO; //removes camera controlls
        [self presentViewController:imagePickerController animated:NO completion:nil];
    }

    else{

    }

}

-(void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [self dismissViewControllerAnimated:YES completion:nil];
}

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
    self.imageView.image = image;
    [self dismissViewControllerAnimated:YES completion:nil];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

1 个答案:

答案 0 :(得分:0)

您无法使用UIView以自定义UIImagePickerController展示相机。您需要使用AVFoundation框架在自定义UIView中展示相机。