Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(iOS) overlay view supporting to show the indicated image titled "overl… #715

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/ios/CDVCamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ typedef NSUInteger CDVMediaType;
@property (strong) NSMutableDictionary *metadata;
@property (strong, nonatomic) CLLocationManager *locationManager;
@property (strong) NSData* data;
@property (assign) BOOL isOverlayView;
@property (strong) UIView* overlayView;

/*
* getPicture
Expand All @@ -101,6 +103,8 @@ typedef NSUInteger CDVMediaType;
* quality: integer between 1 and 100
*/
- (void)takePicture:(CDVInvokedUrlCommand*)command;
- (void)takePictureOverlayView:(CDVInvokedUrlCommand*)command;

- (void)cleanup:(CDVInvokedUrlCommand*)command;
- (void)repositionPopover:(CDVInvokedUrlCommand*)command;

Expand Down
29 changes: 28 additions & 1 deletion src/ios/CDVCamera.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ + (void)initialize
org_apache_cordova_validArrowDirections = [[NSSet alloc] initWithObjects:[NSNumber numberWithInt:UIPopoverArrowDirectionUp], [NSNumber numberWithInt:UIPopoverArrowDirectionDown], [NSNumber numberWithInt:UIPopoverArrowDirectionLeft], [NSNumber numberWithInt:UIPopoverArrowDirectionRight], [NSNumber numberWithInt:UIPopoverArrowDirectionAny], nil];
}

@synthesize hasPendingOperation, pickerController, locationManager;
@synthesize hasPendingOperation, pickerController, locationManager, isOverlayView;

- (NSURL*) urlTransformer:(NSURL*)url
{
Expand Down Expand Up @@ -138,6 +138,7 @@ - (BOOL)popoverSupported

- (void)takePicture:(CDVInvokedUrlCommand*)command
{
isOverlayView = NO;
self.hasPendingOperation = YES;
__weak CDVCamera* weakSelf = self;

Expand Down Expand Up @@ -183,6 +184,12 @@ - (void)takePicture:(CDVInvokedUrlCommand*)command
}];
}

- (void)takePictureOverlayView:(CDVInvokedUrlCommand*)command
{
isOverlayView = YES;
[self takePicture:command];

}
- (void)showCameraPicker:(NSString*)callbackId withOptions:(CDVPictureOptions *) pictureOptions
{
// Perform UI operations on the main thread
Expand All @@ -195,6 +202,26 @@ - (void)showCameraPicker:(NSString*)callbackId withOptions:(CDVPictureOptions *)
// we need to capture this state for memory warnings that dealloc this object
cameraPicker.webView = self.webView;

//It's a overlay view block to show the indicated image titled "overlayImage.png"
if(isOverlayView) {
NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"CDVCamera" withExtension:@"bundle"];
NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
NSString *imagePath = [bundle pathForResource:@"overlayImage" ofType:@"png"];
UIImage *imgSrc = [UIImage imageWithContentsOfFile:imagePath];
UIButton *btnOverlay = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, self.pickerController.view.bounds.size.width, self.pickerController.view.bounds.size.height)];
[btnOverlay setImage:imgSrc forState:UIControlStateNormal];
[btnOverlay setImage:imgSrc forState:UIControlStateSelected];
[btnOverlay setContentMode:UIViewContentModeCenter];
[self.overlayView addSubview:btnOverlay];
[self.overlayView.layer setOpaque:YES];
self.overlayView.opaque = NO;
[self.overlayView setBackgroundColor:UIColor.clearColor];
[self.overlayView setTintColor:UIColor.clearColor];
[self.overlayView setAlpha:1.0];
[self.overlayView setBackgroundColor:UIColor.whiteColor];
pickerController.cameraOverlayView = self.overlayView;
}

// If a popover is already open, close it; we only want one at a time.
if (([[self pickerController] pickerPopoverController] != nil) && [[[self pickerController] pickerPopoverController] isPopoverVisible]) {
[[[self pickerController] pickerPopoverController] dismissPopoverAnimated:YES];
Expand Down