问题描述
我有一个build 1和build 2完成。
Build 1 - 一个简单的空白屏幕,有两个对齐约束的文本框
Build 2 - 当应用程序运行时,它调用IOS的本机后置摄像头设备。
我的第三个版本是这两个以前的版本一起作为一个,其中本机相机显示实时视频馈送,覆盖的是两个文本框及其对齐约束。
我不确定如何将两位代码放在一起。
Build 1 --.h文件
#import< UIKit /UIKit.h>
@interface ViewController:UIViewController
@property(强,非原子)IBOutlet UIView * TestTextBox;
@property(weak,nonatomic)IBOutlet UITextView * TestTetBox2;
@end
Build 1 --.m文件
#importViewController.h
@interface ViewController()
@end
@implementation ViewController
@synthesize TestTextBox;
@synthesize TestTetBox2;
- (void)viewDidLoad {
[super viewDidLoad];
//在加载视图之后执行任何其他设置,通常来自nib。
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
//处理可以重新创建的任何资源。
}
@end
Build 2 --.h文件
#import< UIKit / UIKit.h>
@interface ViewController:UIViewController< UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property(强,非原子)IBOutlet UIImageView * imageView;
@end
Build 2 --.m file
#importViewController.h
@interface ViewController()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
//在加载视图之后执行任何其他设置,通常来自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; // Defualt to Native Camera View
imagePickerController.showsCameraControls = NO; // removed cameras controlss
[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];
//处理可以重新创建的任何资源。
}
@end
您不能使用 UIImagePickerController
在自定义 UIView
您需要使用 AVFoundation
框架在自定义 UIView
中显示摄像机。
Having trouble carrying out a build I am trying to complete.
I have the build 1 and build 2 complete.
Build 1 - A simple blank screen with two text boxes with alignment constraints
Build 2 - When application is run it calls the native back camera of an IOS device.
My third build is these two previous builds together as one, where the native camera shows a live video feed and over layed is the two text boxes with their alignment constraints.
I am unsure how to bring the two bits of code together.
The code i currently have:
Build 1 - .h File
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIView *TestTextBox;
@property (weak, nonatomic) IBOutlet UITextView *TestTetBox2;
@end
Build 1 - .m file
#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
Build 2 - .h file
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController <UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property (strong, nonatomic) IBOutlet UIImageView *imageView;
@end
Build 2 - .m file
#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
You cannot present the camera in a custom UIView
using the UIImagePickerController
. You need to use AVFoundation
framework to present a camera in a custom UIView
.
这篇关于如何在IOS中的本机相机视图上覆盖文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!