I'm attempting to write an application that shows the camera feed, and you can take an image from it. I've successfully set up a UIButton and a linked action method (IBAction) but I'm having trouble making it trigger the UI to save the picture. I have it all set up so when everything goes correctly it should inform the user, but instead it crashes. Any insight would be greatly appreciated.
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(applicationDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
- (void)applicationDidBecomeActive
{
//Start the camera up
UIImagePickerController *imageViewPickerController = [[UIImagePickerController alloc] init];
//Hide default UI elements
imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imageViewPickerController.showsCameraControls = NO;
imageViewPickerController.navigationBarHidden = YES;
imageViewPickerController.toolbarHidden = YES;
//Start the button overlay
UIView *btnView = [[UIView alloc] initWithFrame:imageViewPickerController.view.bounds];
btnView.opaque = NO;
btnView.clipsToBounds = YES;
//Start up the button
UIButton *snapButton = [[UIButton alloc] initWithFrame:CGRectMake(-6, 504, 65, 65)];
snapButton.alpha = 0.5;
snapButton.transform = CGAffineTransformMakeRotation(DEGREES_RADIANS(90));
[snapButton addTarget:snapButton action:#selector(takePhoto:) forControlEvents:UIControlEventTouchUpInside];
//Set the button's picture
UIImage *snapButtonImage = [UIImage imageNamed:#"Button.png"];
[snapButton setImage:snapButtonImage forState:UIControlStateNormal];
//Add button to the overlay
[btnView addSubview:snapButton];
//Overlay button view
imageViewPickerController.cameraOverlayView = btnView;
//Fix for iPhone 5 and make fullscreen
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -55.0);
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333);
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));
CGAffineTransform transform = CGAffineTransformConcat(translate, scale);
transform = CGAffineTransformConcat(transform, rotate);
imageViewPickerController.cameraViewTransform = transform;
//Let's present it all
[self presentViewController:imageViewPickerController
animated:NO
completion:NULL];
}
- (IBAction)takePhoto:(id)sender {
[UIImagePickerController takePicture];
}
-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Save image
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"Image saved to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
EDIT:
Revised code to resolve exception.
- (void)applicationDidBecomeActive
{
//Start the camera up
_imageViewPickerController = [[UIImagePickerController alloc] init];
//Hide default UI elements
_imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
_imageViewPickerController.showsCameraControls = NO;
_imageViewPickerController.navigationBarHidden = YES;
_imageViewPickerController.toolbarHidden = YES;
//Start the button overlay
UIView *btnView = [[UIView alloc] initWithFrame:_imageViewPickerController.view.bounds];
btnView.opaque = NO;
btnView.clipsToBounds = YES;
//Start up the button
UIButton *snapButton = [[UIButton alloc] initWithFrame:CGRectMake(-6, 504, 65, 65)];
snapButton.alpha = 0.5;
snapButton.transform = CGAffineTransformMakeRotation(DEGREES_RADIANS(90));
[snapButton addTarget:snapButton action:#selector(snapThat) forControlEvents:UIControlEventTouchUpInside];
//Set the button's picture
UIImage *snapButtonImage = [UIImage imageNamed:#"Button.png"];
[snapButton setImage:snapButtonImage forState:UIControlStateNormal];
//Add button to the overlay
[btnView addSubview:snapButton];
//Overlay button view
_imageViewPickerController.cameraOverlayView = btnView;
//Fix for iPhone 5 and make fullscreen
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -55.0);
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333);
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));
CGAffineTransform transform = CGAffineTransformConcat(translate, scale);
transform = CGAffineTransformConcat(transform, rotate);
_imageViewPickerController.cameraViewTransform = transform;
//Let's present it all
[self presentViewController:_imageViewPickerController
animated:NO
completion:NULL];
}
- (void)snapThat {
[_imageViewPickerController takePicture];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Save image
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image:didFinishSavingWithError:contextInfo:), nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
UIAlertView *alert;
// Unable to save the image
if (error)
alert = [[UIAlertView alloc] initWithTitle:#"Error"
message:#"Unable to save image to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
else // All is well
alert = [[UIAlertView alloc] initWithTitle:#"Success"
message:#"Image saved to Photo Album."
delegate:self cancelButtonTitle:#"Ok"
otherButtonTitles:nil];
[alert show];
}
EDIT 2: Including headers
#interface TurnikitViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
#property (strong, nonatomic) IBOutlet UIView *imageView;
#property (strong, nonatomic) UIImagePickerController *imageViewPickerController;
#end
You should have this as property:
#property (strong, nonatomic) UIImagePickerController *imageViewPickerController;
then you init that as you are doing:
_imageViewPickerController = [[UIImagePickerController alloc] init];
and when you save:
[_imageViewPickerController takePicture];
Instead now, you are not calling the method on the instance, but on the class..that is an error:
[UIImagePickerController takePicture];
And also, you are adding as target of your button, itself..instead the target is self:
[snapButton addTarget:self action:#selector(snapThat) forControlEvents:UIControlEventTouchUpInside];
Related
I am new in iOS and I am facing problem to add UIscrollview on UIImage in UIAlertView.
My code is Like this
In ViewDidLoad
newsimage.userInteractionEnabled=YES;
UILongPressGestureRecognizer *longpressgestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
[longpressgestureRecognizer addTarget:self action:#selector(imgLongPressed:)];
longpressgestureRecognizer.delegate = self;
[newsimage addGestureRecognizer: longpressgestureRecognizer];
- (void) imgLongPressed:(UILongPressGestureRecognizer*)sender
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
CGSize size = CGSizeMake(200, 200); // set the width and height
UIImage *resizedImage = [self resizeImage:newsimage.image imageSize:size];
UIImage *wonImage = resizedImage;
imageView.contentMode=UIViewContentModeCenter;
[imageView setImage:wonImage];
alertViewpress = [[UIAlertView alloc] initWithTitle:#""
message:#""
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil];
//check if os version is 7 or above
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[alertViewpress setValue:imageView forKey:#"accessoryView"];
}else{
[alertViewpress addSubview:imageView];
}
[alertViewpress show];
[self performSelector:#selector(dismiss:) withObject:alertViewpress afterDelay:1.0];
}
- (void)willPresentAlertView:(UIAlertView *)alertView {
[alertView setFrame:CGRectMake(0, 0, 200, 200)];
}
-(void)dismiss:(UIAlertView*)alert
{
[alert dismissWithClickedButtonIndex:0 animated:YES];
}
-(UIImage *)resizeImage:(UIImage *)image imageSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0,0,size.width,size.height)];
UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
// here is the scaled image which has been changed to the size specified
UIGraphicsEndImageContext();
return newImage;
}
How can I add Scroll view so that I can scroll image or How can I change size of UIAlertView or is it is possible to change the size of UIAlertView.Thanks in Advance!
I give you what you ask.Your view name is customView and you set frame for that.Now the code looks like below.
UILongPressGestureRecognizer *longPressOnCustomView = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:#selector(longPressOnCustomView:)];
longPressOnCustomView.delegate = self;
customView.userInteractionEnabled = YES;
[customView addGestureRecognizer:longPressOnCustomView];
#pragma mark Long Press Gesture Recognizer
- (void)longPressOnCustomView:(UILongPressGestureRecognizer*)gesture
{
if (gesture.state == UIGestureRecognizerStateEnded)
{
//Code for scrolling the image
}
}
I want to develop a application in which user can change there hair style. so i add a overlay in camera view by using following code files and try to combine both image.
Here is my ViewController.h file
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIPopoverControllerDelegate>{
UIImagePickerController *imagePicker;
UIPopoverController *popoverController;
NSData *imageData;
}
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#end
and ViewController.m file
#import "ViewController.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// assign action to button
UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
myButton.frame = CGRectMake(0, 0, 200, 60);
myButton.center = self.view.center;
[myButton addTarget:self action:#selector(buttonPress:) forControlEvents:UIControlEventTouchUpInside];
[myButton setTitle:#"Image Picker" forState:UIControlStateNormal];
[self.view addSubview:myButton];
}
- (void)buttonPress:(id)sender {
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
// alert the user that the camera can't be accessed
UIAlertView *noCameraAlert = [[UIAlertView alloc] initWithTitle:#"No Camera" message:#"Unable to access the camera!" delegate:nil cancelButtonTitle:#"Dismiss" otherButtonTitles:nil, nil];
[noCameraAlert show];
} else {
// prepare imagePicker view
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
imagePicker.delegate = self;
imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
imagePicker.navigationBarHidden = YES;
imagePicker.toolbarHidden = YES;
imagePicker.extendedLayoutIncludesOpaqueBars = YES;
// create view for overlay
CGRect overlayRect = CGRectMake(0, 0, imagePicker.view.frame.size.width, imagePicker.view.frame.size.height-50);
UIView *overlayView = [[UIView alloc] initWithFrame:overlayRect];
// prepare the image to overlay
UIImageView *overlayImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"wig"]];
overlayImage.center = overlayView.center;
//overlayImage.alpha = 0.5;
[overlayView addSubview:overlayImage];
// add the image as the overlay
[imagePicker setCameraOverlayView:overlayView];
// display imagePicker
[self.navigationController presentViewController:imagePicker animated:YES completion:nil];
}
}
#pragma mark - UIBarButton Selectors
- (void)takePictureButtonPressed:(id)sender {
NSLog(#"takePictureButtonPressed...");
// TODO: take picture!
[self presentViewController:imagePicker animated:YES
completion:^ {
[imagePicker takePicture];
}];
}
- (void)startStopButtonPressed:(id)sender {
NSLog(#"startStopButtonPressed...");
// TODO: make this do something
}
- (void)timedButtonPressed:(id)sender {
NSLog(#"timedButtonPressed...");
// TODO: implement timer before calling takePictureButtonPressed
}
- (void)cancelButtonPressed:(id)sender {
NSLog(#"cancelButtonPressed");
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - UIImagePickerController Delegate Methods
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)editingInfo {
[picker dismissViewControllerAnimated:YES completion:NULL];
[popoverController dismissPopoverAnimated: YES];
NSData *image1 = UIImageJPEGRepresentation([editingInfo valueForKey:UIImagePickerControllerOriginalImage],1.0);
UIImage *Imgg = [self addOverlayToBaseImage:[editingInfo valueForKey:UIImagePickerControllerOriginalImage]];
image1 = UIImageJPEGRepresentation(Imgg,1.0);
imageData = image1;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath =[documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:#"%#.png",#"cached"]];
NSLog((#"pre writing to file"));
if (![imageData writeToFile:imagePath atomically:NO])
{
NSLog((#"Failed to cache image data to disk"));
}
else
{
[[NSUserDefaults standardUserDefaults] setValue:imagePath forKey:#"imagePath"];
NSLog(#"the cachedImagedPath is %#",imagePath);
}
[self.imageView setImage:Imgg];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIImage*)addOverlayToBaseImage:(UIImage*)baseImage{
UIImage *overlayImage = [UIImage imageNamed:#"wig.png"];
CGPoint topCorner = CGPointMake(0, 0);
CGSize targetSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);
CGRect scaledRect = CGRectZero;
CGFloat scaledX = self.view.frame.size.height * baseImage.size.width / baseImage.size.height;
CGFloat offsetX = (scaledX - self.view.frame.size.width) / -2;
scaledRect.origin = CGPointMake(offsetX, 0.0);
scaledRect.size.width = scaledX;
scaledRect.size.height = self.view.frame.size.height;
UIGraphicsBeginImageContext(targetSize);
[baseImage drawInRect:scaledRect];
[overlayImage drawAtPoint:topCorner];
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
#end
This code combine both image but i want the exact same image which user can see in camera preview. My problem is when i capture image and see image in UIImageview its totally different from camera preview.
Camera Preview Image
What i get
Help me to get same image like Camera preview.
I was also facing the same issue. I have fixed this issue here you can find my complete git repo
Camera Preview Image
What i get
I have several buttons. When either of the buttons are pressed it pops up and alertView asking the user to take a photo or select from the camera roll. Now the issue I am having is that I have 12 buttons and 12 UIImageViews. All buttons have there own action which pops the alert and allows the user to choose either of the options. Now in didFinishPickingMediaWithInfo method I pass the image from the camera or the camera roll to the first imageView. This all works fine, however if I want to select button 2 which fires the another alert with another tag i want to set imageView 2 and so on so on (Not replace imageView1). I need a way to distinguish in the didFinishPickingMediaWithInfo what imageView to set based on the button selection which popped the alert. Because at the moment the first image view is only getting set and reset if I choose another button which should set the corresponding image.
Heres the action for the button.
-(IBAction) addPhoto1:(id) sender {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Image Source" message:#"Take a photo or select a previously taken photo" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Take Photo", #"Select Photo", nil];
[alert show];
alert.tag = 101;
[alert release];
}
And alert clickedButtonAtIndex:
- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (alert.tag == 101) {
if (buttonIndex == 1) {
//Take photo
[self performSelector:#selector(takePicture:) withObject:nil afterDelay:0.0];
}
else if (buttonIndex == 2){
//Camera roll
[self performSelector:#selector(pictureAlbum:) withObject:nil afterDelay:0.0];
}
else if (buttonIndex == 0) {
NSLog(#"Cancel");
}
}
}
And here's the didFinishPickingMediaWithInfo:
-(void) imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[image CGImage] metadata:dict completionBlock:nil];
if (addFirstImage.tag == 1001) {
firstImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
firstImage.layer.cornerRadius = 5;
firstImage.layer.masksToBounds = YES;
}
if (addSecondImage.tag == 1002) {
secondImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
secondImage.layer.cornerRadius = 5;
secondImage.layer.masksToBounds = YES;
}
}
}
Now obviously this is not right whats the best way to set the correct imageViews image based on the button from the Alert that was originally pressed? (addFirstImage and addSecondImage are both buttons linked via IB)
Many thanks
Why don't you use action's `sender' to 'remembers' which Button was pressed first ?
Using IBOutletCollections, ordered with same indexes :
#property (...) IBOutletCollection(UIButton) allYourButtons;
#property (...) IBOutletCollection(UIImageView) allYourImageViews;
// I suppose that both Collections objects have 'tags' (set in XIB file)
// a UIButton and the corresponding UIImageVIew have the SAME tag
#property (...) NSInteger clickedButtonIndex;
- (IBAction) imageViewWasPressed:(id)sender
{
//keep a reference to the specific button that launched the action
self.clickedButtonIndex = [(UIButton *)sender tag];
[self presentAlertViewForPictureChoice];
}
Then, you use clickedButtonIndex in your UIAlertView delegate method to find which UIImageVIew from allYourImageViews should have its image updated...
- (UIImageView *)imageToUpdateForSelectedIndex:(NSInteger)anIndex
{
UIImageView *result = nil;
for (UIImageView *imageView in self.allYourImageViews){
if(imageView.tag == anIndex){
result = imageView;
break;
}
}
return result;
}
(EDIT)
Ok, another way to associate a UIButton with a UIImageView is to create a subclass
// a new UIButton subclass
ButtonWithImageView : UIButton
#property (...) IBOutlet UIImageView *relatedImageView;
//IBOutlet enables you to directly link a Button with its imageVIew in your XIB
// in your controller
#property (...) ButtonWithImageView *selectedButton;
- (IBAction)buttonWasPressed:(id)sender
{
...
self.selectedButton = (ButtonWithImageView *)sender;
}
Then all you have to do is edit self.selectedButton.relatedImageView
Ok I figured out how to do this. Firstly I created an ivar int called myTag in interface file
int myTag;
I then tagged all my buttons with tag number i.e button1.tag = 1001 (to 1012 for my 12 buttons) in viewDidLoad,
I then created the one Action as opposed to 12 for each button. And connect all to this one action via IB.
- (IBAction)takePhoto:(UIButton*)sender {
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Image Source" message:#"Take a photo or select a previously taken photo" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:#"Take Photo", #"Select Photo", nil];
[alert show];
alert.tag = 101;
[alert release];
if (sender.tag == 1001){
NSLog(#"You clicked button 1");
myTag = 1001;
}
if (sender.tag == 1002){
NSLog(#"You clicked button 2");
myTag = 1002;
}
}
I then detect what button was pressed and pass an int value to myInt ivar
and then in my didFinishPickingMediaWithInfo I do this!
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImage *image = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeImageToSavedPhotosAlbum:[image CGImage] metadata:dict completionBlock:nil];
if (myTag == 1001){
firstImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
firstImage.layer.cornerRadius = 5;
firstImage.layer.masksToBounds = YES;
}
if (myTag == 1002) {
secondImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
secondImage.layer.cornerRadius = 5;
secondImage.layer.masksToBounds = YES;
}
[picker dismissModalViewControllerAnimated:YES];
}
All working perfectly! Many thanks for your help though!
Essentially I have a UIAlertView that pops up. When a user selects a button it calls itself, and based on the button index it brings up a UIImageView subview. My question is, because the UIImageView takes up a good portion of the screen it lays on top of the UIAlertView, so the cancel button is unseen. I was wondering if I could create actions on the UIImageView so that if it is clicked or touched up inside, the UIAlertView/UIImageView would resign and disappear?
Someone please help, I've been tooling around this for hours.
Here is the code from the button being clicked, and the button index.
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == 0)
{
// exit(0);
}
else
{
UIAlertView *successAlert = [[UIAlertView alloc] initWithTitle:#"molecule" message:molURL delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 280, 260)];
NSString *MyURL = molURL;
NSString *apURL = [NSString stringWithFormat:#"%#",MyURL];
NSURL * imageURL = [NSURL URLWithString:apURL];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage * image1 = [UIImage imageWithData:imageData];
//UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];
[imageView setImage:image1];
[successAlert addSubview:imageView];
[successAlert show];
}
}
MyImageView.h
#import <UIKit/UIKit.h>
#interface MyImageView : UIImageView {
}
#end
MyImageView.m
#import "MyImageView.h"
#implementation MyImageView
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.userInteractionEnabled=YES;
}
return self;
}
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[UIView animateWithDuration:2.0f animations:^(void) {
self.alpha=0.0f;
super.hidden =YES;
UIAlertView *alert=(UIAlertView*)self.superview;
alert.alpha=0.0f;
[alert dismissWithClickedButtonIndex:0 animated:YES];
//or
//[alert removeFromSuperview];
}];
}
- (void)dealloc {
[super dealloc];
}
#end
MyViewController.h
#class MyImageView;
MyViewController.m
#import "MyImageView.h"
then while create imageView
MyImageView *specialImageView =[[MyImageView alloc]initWithFrame:CGRectMake(0, 0, 280, 260)];
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.