问题
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
回答1:
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
.
来源:https://stackoverflow.com/questions/34592893/how-do-i-overlay-a-text-box-over-a-native-camera-view-in-ios