Custom view for taking image though camera in ios 7 - iphone

//---------- viewController.h file has
IBOutlet UIView *viewCamera; // custom view for taking camera reason
//------------viewController.m :: inside viewDidLoad method
// -- camera start
[viewCamera setBackgroundColor:[UIColor clearColor]];
imgPicker = [UIImagePickerController new];
imgPicker.allowsEditing = YES;
imgPicker.delegate = self;
imgPicker.cameraOverlayView = viewCamera;
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imgPicker animated:NO completion:nil];
// ----- ob btn clicked
- (IBAction)btnTakePhotoPressed:(id)sender{
[imgPicker takePicture];
}
App is crashed due to this line, if I comment this line code is running but camera is open in full view, I want to add my camera access on my custom view.
imgPicker.cameraOverlayView = viewCamera;
Thanks in advance :)

Related

Access/Reference imageView.image to replace it later

Alright, this has been driving me insane for the last few days. I hope this is an easy fix. I am trying to access my UIImageView.image so I can replace it later.
With only the needed code here it is:
I first create an imageView for each time a user clicks on a photo in their Library.
// .h
#property (strong,nonatomic) UIImage *doneImage;
#property (strong,nonatomic) UIImageView *editImage;
// .m
#synthesize doneImage;
#synthesize editImage;
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *originalImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(xCoordinate, yCoordinate, widthOfImage, heightOfImage)];
imgView.image = originalImage;
imgView.userInteractionEnabled = YES;
[self.mainView addSubview:imgView];
// I add gestures
longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:#selector(handleLongPress:)];
longPress.minimumPressDuration = 1;
longPress.numberOfTouchesRequired = 1;
[imgView addGestureRecognizer:longPress];
}
When someone clicks holds down on one of those images this pops up
- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer {
editImage = (UIImageView*)recognizer.view; // I declare what editImage is and now have access to what imageView is being interacted with.
doneImage = editImage.image; // I then get the image of that for later use.
if(UIGestureRecognizerStateBegan == recognizer.state) {
popoverEditor = [[UIPopoverController alloc] initWithContentViewController:[self.storyboard instantiateViewControllerWithIdentifier:#"popupEditor"]];
[popoverEditor presentPopoverFromRect:editImage.bounds inView:editImage permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
This pops up a menu with 4 buttons. I then have an IBAction that tries to fire up the editing part.
- (IBAction)effectsEditorButton:(id)sender {
// editImage is my imageView
if (editImage == nil) {
NSLog(#"imageView was nil wtf");
} else {
[self performSelector:#selector(editImageWithEffects:)];
}
}
My image view is ALWAYS nil. I need to get a reference to that somehow. I've tried tags but I can't seem to get them to hold their value once I get to this point.
Any help would be very much Appreciated. Thanks!
Are you leaving out code? Based on what you have here, editImage will always be null because it isn't declared anywhere (perhaps something in Interface Builder that we can't see?).
You need a way to link back into your view controller from your popover. Popular ways to do this are to use a completion block when returning from your popover controller, or setting your "main" VC as a weak property on the popover.

ViewController as Subview

I have one UIViewController (DownloadManager) which downloads a webpage with UIWebView and display the downloaded content (say a pdf file). I want to use it as reusable component.
I am having another UIViewController pointing to a screen which contains 4 buttons each button should download and display one pdf file from webpage. I want to display the downloaded pdf as a embedded subview to the current screen. Basically don't want navigation.
Here I tried to use DownloadManager as subview and display pdf as subview. Its working fine.
I read as Per screen one View Controller. But still can I use this approach ?
I have to send a email feedback from this screen. As soon as I present the MFMailComposeViewController the previous download manager subview disappears Technically what is happening here?
Please find the code snippet below:
//************************************************
#implement MyViewController
- (void) initWebView
{
downloadMgr = [[DownLoadViewController alloc] initWithNibName:#"DownLoadViewController" bundle:nil];
downloadMgr.view.frame = CGRectMake(140, 20, 300, 200);
downloadMgr.WebView.frame = CGRectMake(140, 20, 300, 200);
downloadMgr.view.backgroundColor = [UIColor whiteColor];
downloadMgr.WebView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:downloadMgr.view];
[self.view addSubview:downloadMgr.WebView];
}
----
----
- (IBAction)onHomeClick:(UIButton *)sender
{
switch (sender.tag)
{
case 101:
{
[self stopWebViewResources];
if (!downloadMgr) {
[self initWebView];
}
downloadMgr.NavigationURL = [[NSURL alloc] initWithString:#"https://xxx.yyyyyy.com/sites/pex/iPadFiles/abc.pdf"];
downloadMgr.title = #"ABC";
[downloadMgr LoadURL];
}
break;
case 120:
{
//Send feedback via email
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
----
----
mail.modalPresentationStyle = UIModalPresentationFullScreen;
[self presentModalViewController:mail animated:YES];
}
}
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
#end
//*****************************************************************
#interface DownLoadViewController : UIViewController <MyWebViewDelegate>{
NSURL* NavigationURL;
IBOutlet myWebView* WebView;
IBOutlet UIActivityIndicatorView* ProgressView;
NSString* DownloadedFileName;
}
It is much more robust to separate the download functionality and the display into two different classes.
Ideally, you should have a class like "Downloader" or "Download Manager" which is a subclass of NSObject. This class should do the download and notify its delegate when it is done. Then you can have as many UIViewControllers as you like that take advantage of your Downloader class.

How to navigate the view in iphone programming?

In my appController's ViewDidLoad, I have done some thing as below
- (void)viewDidLoad
{
self.overlayViewController =
[[[OverlayViewController alloc] initWithNibName:#"OverlayViewController" bundle:nil] autorelease];
// as a delegate we will be notified when pictures are taken and when to dismiss the image picker
self.overlayViewController.delegate = self;
self.capturedImages = [NSMutableArray array];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
// camera is not on this device, don't show the camera button
NSMutableArray *toolbarItems = [NSMutableArray arrayWithCapacity:self.myToolbar.items.count];
[toolbarItems addObjectsFromArray:self.myToolbar.items];
[toolbarItems removeObjectAtIndex:2];
[self.myToolbar setItems:toolbarItems animated:NO];
}
}
I have two methods as below,
- (IBAction)cameraAction:(id)sender
{
[self showImagePicker:UIImagePickerControllerSourceTypeCamera];
}
- (void)showImagePicker:(UIImagePickerControllerSourceType)sourceType
{
if (self.imageView.isAnimating)
self.imageView.stopAnimating;
if (self.capturedImages.count > 0)
[self.capturedImages removeAllObjects];
if ([UIImagePickerController isSourceTypeAvailable:sourceType])
{
[self.overlayViewController setupImagePicker:sourceType];
[self presentModalViewController:self.overlayViewController.imagePickerController animated:YES];
}
}
Now as I click the button, the method will launch the class showing custom view, I want to call this without clicking the button, what should I do ?
I wrote the button coding directly in ViewDidLoad, but not working at all
This code, I took from apple's documentation as example
Help !
If I understand correctly, you are wanting to show a view?
If so you could push using:
[self.navigationcontroller pushviewcontroller:YOURVIEWCONTROLLER animated:YES];
Or you could present it using:
[self presentModalViewControllerpushviewcontroller:YOURVIEWCONTROLLER animated:YES];

presentModalViewController doesn't rotate properly in iPhone / iPad

I have a viewController called MainViewController, which has a UIButton. When tapped, this button loads another viewController, called ModalSelector like this:
- (IBAction)showModalSelector:(id)sender {
ModalSelector *modal = [[ModalSelector alloc]
initWithNibName:#"modalSelector" bundle:nil];
modal.modalPresentationStyle = UIModalPresentationFormSheet;
modal.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
modal.modalInPopover = YES;
modal.issues = issuesForModal;
modal.parent = self;
[self presentModalViewController:modal animated:YES];
[modal.view setFrame:CGRectMake(-80, 20, 700, 400)];
[issuesForModal release];
[modal release];
}
However, when I rotate the device in the simulator, neither view rotates properly, even though I have this in both viewControllers:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
How can I make it rotate properly?
Thanks
I've discovered there's not a problem with the code, but with the simulator itself. When I test it on the actual device, it works perfectly.

Using UIImagePickerController in the game

I want to make a game, where the user can touch a picture of a TV and then choose a picture from their photo library.
I had success working with UITextFields, adding them to my EAGLView as subviews But I haven't been able to do the same thing with an UIImagePickerController , which seems the only way to do what I want to do.
Any help is appreciated !
UPDATE
With the suggestion of zpasternack I managed to make the menu appear by adding the UIImagePickerControllerDelegate, UINavigationControllerDelegate and using this method:
- (void) chooseImageFromLibrary {
if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] ) return;
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.allowsEditing = YES;
[self addSubview:imagePickerController.view];
[imagePickerController viewWillAppear:YES];
[imagePickerController viewDidAppear:YES];
}
I call the chooseImageFromLibrary method at the start. It shows the interface, but as soon as i hit cancel or choose the app stops.
Can anyone suggest me:
1) How to make the cancel and choose buttons work.
2) How to call the UIImagePickerController whenever I want ( by calling chooseImageFromLibrary again ??).
3) When the user hits choose..Where do i find the UIImage the user just picked to ?, how do i pick it ?
Thanks.
I've never used one over an EAGLView, but UIImagePickerControllers are typically invoked with presentModalViewController, like:
- (void) chooseImageFromLibrary {
if( ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] ) return;
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.allowsEditing = YES;
[self presentModalViewController:imagePickerController animated:YES];
}
Nervermind, problem solved. i just needed to overwrite some functions to make use of the UIImagePickerController.