如何在IOS中将文本框覆盖在本机相机视图上

如何在IOS中将文本框覆盖在本机相机视图上,ios,objective-c,text,camera,native,Ios,Objective C,Text,Camera,Native,在执行我试图完成的构建时遇到问题 我已经完成了构建1和构建2 构建1-一个简单的空白屏幕,带有两个带有对齐约束的文本框 构建2-当应用程序运行时,它调用IOS设备的本机后台摄像头 我的第三个构建是前两个构建合为一个,其中本机摄影机显示一个实时视频提要,而重叠的是两个文本框及其对齐约束 我不确定如何将这两位代码组合在一起 我目前拥有的代码: 生成1-.h文件 #import <UIKit/UIKit.h> @interface ViewController : UIViewContr

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

我已经完成了构建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
构建2-.h文件

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate>

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


@end
#导入
@界面ViewController:UIViewController
@属性(强,非原子)IBUIImageView*imageView;
@结束
构建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
#导入“ViewController.h”
@界面视图控制器()
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
}
-(无效)视图显示:(BOOL)动画{
[超级视图显示:动画];
if(self.imageView.image==nil){
UIImagePickerController*imagePickerController=[[UIImagePickerController alloc]init];
imagePickerController.modalPresentationStyle=UIModalPresentationCurrentContext;
imagePickerController.delegate=self;
imagePickerController.sourceType=UIImagePickerController源类型Camera;//解除对本机相机视图的限制
imagePickerController.showsCameraControls=NO;//删除相机控件
[self-presentViewController:imagePickerController已设置动画:未完成:无];
}
否则{
}
}
-(无效)ImagePickerController IDCancel:(UIImagePickerController*)选择器{
[自我解除视图控制器激活:是完成:无];
}
-(void)imagePickerController:(UIImagePickerController*)picker未使用信息完成PickingMediaWithInfo:(NSDictionary*)信息{
UIImage*image=[info-valueForKey:UIImagePickerControllerOriginalImage];
self.imageView.image=图像;
[自我解除视图控制器激活:是完成:无];
}
-(无效)未收到记忆警告{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
@结束

您不能使用
UIImagePickerController在自定义
UIView
中显示摄像头。您需要使用
AVFoundation
framework在自定义
UIView

ok cool!!你知道我如何去纠正这个吗?请跟随,谢谢!我刚刚读了一遍,所以我接下来的步骤就是从这里使用这段代码。我是将其放入ViewController.swift还是AppDelegate.swift?我不需要使用焦距或颜色平衡功能,所以我可以继续到设置部分的末尾吗?你需要的是设置一个预览层并在该层中启动相机会话。嗯,好的,很酷,这很有意义,我以前使用过swift,我只使用过objective c。我应该把这些代码放在我的xcode项目的什么地方?我是这方面的新手,所以需要非常清晰简单的术语来理解
#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