UIImagePickerController and a small custom preview - ios

I want to use an UIImagePickerController non-modally, with a small square preview. However, I get a big black bar at the bottom of the preview, which I can't get rid of (see the screenshot). Why is it there, and how can I get rid of it?
Code:
- (void)viewDidLoad
{
[super viewDidLoad];
_imagePickerVC = [[UIImagePickerController alloc] init];
_imagePickerVC.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePickerVC.mediaTypes = #[ (NSString *)kUTTypeImage ];
_imagePickerVC.wantsFullScreenLayout = NO;
_imagePickerVC.delegate = (id)self;
_imagePickerVC.navigationBarHidden = YES;
_imagePickerVC.allowsEditing = NO;
_imagePickerVC.showsCameraControls = NO;
_imagePickerVC.cameraDevice = UIImagePickerControllerCameraDeviceFront;
CGRect previewFrame = CGRectMake(0, 0, 150, 150);
[_imagePickerVC.view setFrame:previewFrame];
_imagePickerVC.view.autoresizesSubviews = YES;
[self.view addSubview:_imagePickerVC.view];
[_imagePickerVC viewWillAppear:YES];
[_imagePickerVC viewDidAppear:YES];
}

This is a misuse of UIImagePickerController. To make your own image-capture interface, simply use AVFoundation.

Related

xCode Creating UIImagePickerController and Referencing It

for my app I want to create a custom camera overlay and create a UIImagePickerController to start recording video. (below)
- (IBAction)RecordVideo:(UIButton *)sender {
//initialise camera view
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.cameraDevice = UIImagePickerControllerCameraDeviceFront;
cameraUI.showsCameraControls = NO;
cameraUI.navigationBarHidden = YES;
cameraUI.toolbarHidden = YES;
OverlayView *overlay = [[OverlayView alloc]
initWithFrame:CGRectMake(0, 0, 20,20)];
cameraUI.cameraOverlayView = overlay;
[self presentViewController:cameraUI animated:YES completion:nil];
}
as part of the cameraOverlayView I've instantiated a UIButton:
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
//clear the background color of the overlay
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
... some overlay UI stuff
UIButton *captureBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIImage *captureBtnImg = [UIImage imageNamed:#"captureBtn.png"];
[captureBtn setBackgroundImage:captureBtnImg forState:UIControlStateNormal];
captureBtn.frame = CGRectMake(self.frame.size.width/2 - 15,
430,
80,
80);
[self addSubview:captureBtn];
}
return self;
}
So how do I create an IBAction for this button which can then make the UIImagePickerController cameraUI start recording?
If somebody could also explain to me how the IBActions are called from specific buttons only that would also be amazing because that seems like black magic to me?
You can add target like this,
[captureBtn addTarget:self action:#selector(captureBtnclick:) forControlEvents:UIControlEventTouchUpInside];
and you action method shoulbe like this
-(void)captureBtnclick :(UIButton*)sender{
//handle your task on click here
}
second thing why you are adding layer on it? you can use default video recording from imagePicker by setting mediatype like
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
Update accroding to comment
you can use on button click,
[picker startVideoCapture]; //in your case cameraUI i think
Update 2 :
in your .h file,
#property UIImagePickerController *cameraUI;
then in your method RecordVideo use like,
self.cameraUI = [[UIImagePickerController alloc] init];
self.cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
//etc.....
By this way you can use camaraUI in whole class by self
hope this will help :)

the #property showsIndoorMap is invalid in MAMapView of AMap3DMap Pod

- (void)viewDidLoad
{
[super viewDidLoad];
[MAMapServices sharedServices].apiKey = #"xxx";
self.mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds))];
self.mapView.delegate = self;
self.mapView.showsIndoorMap = YES;
self.mapView.showsCompass = NO;
[self.view addSubview:self.mapView];
}
I use the code above to show the map in my app. I want to use "self.mapView.showsIndoorMap = YES;" to show the indoor map but it failed. How can i see the indoor map ?

Rotate a PDF from InAppBrowser

So I was able to integrate InAppBrowser-CE this plugin which works amazingly to display PDF's from a specified window size and give transparency, but now I am trying to figure out how to rotate the PDF. I want to add a rotation tool (similar to the photo library in iOS) but dont know where to start at. I saw something about image rotation tool, but wasnt sure if it applied to a pdf file, and I don't want to keep at something that doesn't work (i.e. using iFrame instead of InAppBrowser to display PDFs) any help is much appreciated. Here is just a sample of how the PDF is called to give you some insight.
This is from HTML to call it to open:
<button onclick="window.open('http://www.free.woodworking-plans.org/images/ranch-house-7161/ranch-house-floor-plan-o.jpg','_blank','vw=685,vh=650,vx=40,vy=40');">Change my size</button>
And here is how the PDF is opened (from xcode CDVInAppBrowser.m)
- (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
{
if (self.inAppBrowserViewController == nil) {
NSString* originalUA = [CDVUserAgentUtil originalUserAgent];
self.inAppBrowserViewController = [[CDVInAppBrowserViewController alloc] initWithUserAgent:originalUA prevUserAgent:[self.commandDelegate userAgent]];
self.inAppBrowserViewController.navigationDelegate = self;
if ([self.viewController conformsToProtocol:#protocol(CDVScreenOrientationDelegate)]) {
self.inAppBrowserViewController.orientationDelegate = (UIViewController <CDVScreenOrientationDelegate>*)self.viewController;
}
}
// set pointer to this viewcontroller for later use
iabvc = self.inAppBrowserViewController;
CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions parseOptions:options];
[self.inAppBrowserViewController showLocationBar:browserOptions.location];
[self.inAppBrowserViewController showToolBar:browserOptions.toolbar];
....
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent
{
self = [super init];
if (self != nil) {
_userAgent = userAgent;
_prevUserAgent = prevUserAgent;
_webViewDelegate = [[CDVWebViewDelegate alloc] initWithDelegate:self];
[self createViews];
}
return self;
}
And here is what the tools section looks like,
self.toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, (self.view.bounds.size.height - TOOLBAR_HEIGHT), self.view.bounds.size.width, TOOLBAR_HEIGHT)];
self.toolbar.alpha = 1.000;
self.toolbar.autoresizesSubviews = YES;
self.toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
self.toolbar.barStyle = UIBarStyleBlackOpaque;
self.toolbar.clearsContextBeforeDrawing = NO;
self.toolbar.clipsToBounds = NO;
self.toolbar.contentMode = UIViewContentModeScaleToFill;
self.toolbar.contentStretch = CGRectFromString(#"{{0, 0}, {1, 1}}");
self.toolbar.hidden = NO;
self.toolbar.multipleTouchEnabled = NO;
self.toolbar.opaque = NO;
self.toolbar.userInteractionEnabled = YES;
I created a rotate button then added this below,
.h
//header - add 'int counter'
#interface CDVInAppBrowserViewController : UIViewController <UIWebViewDelegate>{
#private
NSString* _userAgent;
NSString* _prevUserAgent;
NSInteger _userAgentLockToken;
CDVWebViewDelegate* _webViewDelegate;
int counter;
}
.m
//Add this to the top of the .m file
#define DegreesToRadians(X) ((X) * M_PI / 180.0)
...
//reference
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent
{
counter = 0;
...
//create Rotate Button
NSString* rotateString = #"Rotate";
self.RotateButton = [[UIBarButtonItem alloc] initWithTitle:rotateString style:UIBarButtonItemStylePlain target:self action:#selector(goRotate:)];
self.RotateButton.enabled = YES;
self.RotateButton.imageInsets = UIEdgeInsetsZero;
....
//action - sender
-(IBAction)goRotate:(id)sender
{ counter ++; float angle = (counter%3)*90;
[UIView beginAnimations:#"rotate" context:nil];
[UIView setAnimationDuration:0.5];
self.webView.transform = CGAffineTransformMakeRotation(DegreesToRadians(angle));
[UIView commitAnimations];
}

Why does my CvVideoCamera cover the whole view?

I'm using a CvVideo Camera thus:
- (void)viewDidLoad
{
[super viewDidLoad];
self.videoCamera = [[CvVideoCamera alloc] initWithParentView:imageView];
self.videoCamera.delegate = self;
self.videoCamera.defaultAVCaptureDevicePosition = AVCaptureDevicePositionBack;
self.videoCamera.defaultAVCaptureSessionPreset = AVCaptureSessionPresetiFrame960x540;
self.videoCamera.defaultAVCaptureVideoOrientation = AVCaptureVideoOrientationPortrait;
self.videoCamera.defaultFPS = 30;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.videoCamera start];
}
My storyboard looks like this:
When the view loads, the bar is visible briefly with the rest of the view white. Then when the camera starts it fills the whole screen. Why is it doing this?
Have you tried with a different parent view?
UIView *camView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 300, 400)];
[self.view addSubview:camView];
self.videoCamera = [[CvVideoCamera alloc] initWithParentView:camView];

How to change the size of UIImagePickerController in iPAD?

How to make the UIImagePickerController size bigger in iPAD? Example MAC PhotoBoth application. http://www.youtube.com/watch?v=Ytl3EhNCP_8.
The code already i have done.
- (void)openCamera {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
camera = [[UIImagePickerController alloc] init];
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
camera.cameraDevice = UIImagePickerControllerCameraDeviceFront;
camera.delegate = self;
[self presentViewController:camera sender:nil animated:YES modal:YES];
}
else
{
UIAlertView *objAlert = [[UIAlertView alloc]initWithTitle:#"Alert" message:#"Camera not found" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[objAlert show];
[objAlert release];
}
}
- (void)presentViewController:(UIViewController *)vc
sender:(id)sender
animated:(BOOL)animated
modal:(BOOL)modal {
CGRect cframe = self.capturedImage.bounds;
//cframe = CGRectMake(cframe.origin.x, cframe.origin.y/2.0, 351, 351);
photoPopoverController = [[UIPopoverController alloc] initWithContentViewController:vc];
[photoPopoverController presentPopoverFromRect:[capturedImage bounds] inView:capturedImage permittedArrowDirections:UIPopoverArrowDirectionUnknown animated:YES];
}
You can use transform:
//The transform factor
#define CAMERA_TRANSFORM 0.34 and above
and above, when you want to resize it, use:
camera.wantsFullScreenLayout = YES;
camera.cameraViewTransform = CGAffineTransformScale(camera.cameraViewTransform,CAMERA_TRANSFORM, CAMERA_TRANSFORM);
You should change the frame property of its view.
I.e.
UIView *view = imagePickerController.view;
CGRect frame = view.frame;
frame.size.height = new_height;
frame.size.width = new_width;
view.frame = frame;
It should work. Otherwise, please, give us more detail about how you create the controller, how you display it and which are its delegates.

Resources