How to select Multiselection images in ios - ios

I am making an app for iPhone and want to give users the ability to multi-select images from their photo-library. I already have a working code for user to select four images at a time.But i cant select 2 or 3 images at a time.I want to select the 2 or 3 images at a time.I am trying to the following code.please help me anybody.
- (id)initImagePicker
{
ELCAlbumPickerController *albumPicker = [[ELCAlbumPickerController alloc] initWithStyle:UITableViewStylePlain];
self = [super initWithRootViewController:albumPicker];
if (self)
{
self.maximumImagesCount = 4;
[albumPicker setParent:self];
}
else if (self)
{
self.minimumImageCount=1;
[albumPicker setParent:self];
}
return self;
}
- (id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super initWithRootViewController:rootViewController];
if (self)
self.maximumImagesCount = 4;
else if (self)
self.minimumImageCount=1;
return self;
}
-(void)choosePhotoFromExistingImages
{
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker];
elcPicker.maximumImagesCount = 4;
elcPicker.returnsOriginalImage = NO; //Only return the fullScreenImage, not the fullResolutionImage
elcPicker.imagePickerDelegate = self;
[self presentViewController:elcPicker animated:YES completion:nil];
}

You should try MWPhotoBrowser Control by Michael Waterfall
He has provided single as well as multiple photo selection
Works on iOS 5.1.1+.
All strings are localisable so they can be used in apps that support multiple languages.

In one of my project i've done this thing without ELCImagePickerController. And successfully working that code too. In that project I've added a done button on the navigation bar of image picker controller. Whenever you select a image that image you can grab with in the method called
-(void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)info
Whenever you are finished with picking you images then you press that done button.with in that method dismiss the view controller.
Using this process you can select and fetch as much as image you want to have.
And my app is working successfully.
Cheers....!!!!!!!

Add done button on the navigation bar of uiimagepickercontroller
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if (!doneButton)
{
doneButton = [[UIBarButtonItem alloc] initWithTitle:#"Done"
style:UIBarButtonItemStyleDone
target:self action:#selector(saveImagesDone:)];
}
viewController.navigationItem.rightBarButtonItem = doneButton;
}
First display the image picker using UIImagePickerController
Grab your images
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:#"public.image"]
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Get the data for the image
NSData* imageData = UIImageJPEGRepresentation(image, 1.0);
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// Now we get the full path to the file
NSString* fullPathToFile2 = [self createName:documentsDirectory];
// and then we write it out
[imageData writeToFile:fullPathToFile2 atomically:NO];
}
else
{
// Show Alert
}
}
Close The image picker view controller
-(IBAction)saveImagesDone:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
[self loadimages]; // Load your Images
}
every time you click over an image ,
-(void)imagePickerController:(UIImagePickerController *)pickerdidFinishPickingMediaWithInfo:(NSDictionary *)
info this method will grab the image for you.
Don't forgot to upvote... Cheers....!!!!!

you need to implement these methods
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info;
it will return you array of your image selected.(the controller sends back an array of similarly structured dictionaries)
- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker;

Try this:
-(id)initImagePicker{
ELCAlbumPickerController *albumPicker = [[ELCAlbumPickerController alloc] initWithStyle:UITableViewStylePlain];
self = [super initWithRootViewController:albumPicker];
if (self) {
self.maximumImagesCount = 4;
self.returnsImage = YES;
self.returnsOriginalImage = YES;
[albumPicker setParent:self];
self.mediaTypes = #[(NSString *)kUTTypeImage, (NSString *)kUTTypeMovie];
}
return self;
}
-(id)initWithRootViewController:(UIViewController *)rootViewController
{
self = [super initWithRootViewController:rootViewController];
if (self) {
self.maximumImagesCount = 4;
self.returnsImage = YES;
}
return self;
}
-(void)choosePhotoFromExistingImages
{
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker];
elcPicker.maximumImagesCount = 4;
elcPicker.returnsOriginalImage = NO; //Only return the fullScreenImage, not the fullResolutionImage
elcPicker.imagePickerDelegate = self;
[self presentViewController:elcPicker animated:YES completion:nil];
}

Related

how to combine overlay and camera image together in iOS?

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

UIActivityViewController Copy Ignores imageOrientation

When I take a picture with the phone in Portrait mode, using a UIImagePickerController, the UIImage item that is returned has the top of the image facing left and an imageOrientation property of UIImageOrientationRight , // 90 deg CCW, which is as expected (I think).
When I share the image via a UIActivityViewController, all activities seem to behave correctly except for the Copy activity. When I paste the image into another application (for instance, Messages), the image seems to be ignoring the imageOrientation property.
Has anyone else seen this / found a workaround?
Updated with complete code: (project contains storyboard with a single button mapped to self.takeImageButton and - (IBAction)takeImageAndShare:(id)sender;)
#import "ViewController.h"
#interface ViewController () <UIImagePickerControllerDelegate,UINavigationControllerDelegate>
#property (weak, nonatomic) IBOutlet UIButton *takeImageButton;
#end
#implementation ViewController
- (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.
}
- (IBAction)takeImageAndShare:(id)sender {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.popoverPresentationController.sourceView = self.takeImageButton;
[self presentViewController:imagePicker animated:YES completion:nil];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *chosenImage = info[UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:NULL];
NSLog(#"Image Orientation: %li",chosenImage.imageOrientation);
// Now share the selected image
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[chosenImage] applicationActivities:nil];
activityViewController.modalPresentationStyle = UIModalPresentationPopover;
activityViewController.popoverPresentationController.sourceView = self.takeImageButton;
[self presentViewController:activityViewController animated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}
#end
If you run this code, take a photo with the phone in Portrait (.imageOrientation is 3 = UIImageOrientationRight) and select share activities like Messages, Save Image, etc., the image orientation is correct. If you select the copy activity, the image that gets pasted elsewhere is rotated (top of the image is to the left).
Submitted as Radar 19456881. Complete project is available here.
By Default capture image orientation behavior is UIImageOrientationRight, sp you have to set capture image orientation is
[UIDevice currentDevice].orientation
Based on this post, I decided to create my own copy activity:
//
// PhotoActivityCopy.m
//
// Created by Jeff Vautin on 1/13/15.
// Copyright (c) 2015 Jeff Vautin. All rights reserved.
//
#import "PhotoActivityCopy.h"
#import "ImageKit.h"
#import MobileCoreServices;
#interface PhotoActivityCopy ()
#property (strong,nonatomic) NSData *imageJPEGData;
#end
#implementation PhotoActivityCopy
NSString *PhotoActivityCopyActivityType = #"com.me.uiactivitytype.copy";
NSString *PhotoActivityCopyActivityTitle = #"Copy";
+ (UIActivityCategory)activityCategory
{
return UIActivityCategoryAction;
}
- (NSString *)activityType
{
return PhotoActivityCopyActivityType;
}
- (NSString *)activityTitle
{
return PhotoActivityCopyActivityTitle;
}
- (UIImage *)activityImage
{
CGSize imageSize;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
imageSize = CGSizeMake(76.0, 76.0);
} else {
imageSize = CGSizeMake(60.0, 60.0);
}
return [ImageKit imageOfIconCopyWithExportSize:imageSize];
}
- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
{
BOOL canPerform = NO;
if ([activityItems count] > 1) {
canPerform = NO;
} else if ([[activityItems firstObject] isKindOfClass:[UIImage class]]) {
canPerform = YES;
}
return canPerform;
}
- (void)prepareWithActivityItems:(NSArray *)activityItems
{
self.imageJPEGData = UIImageJPEGRepresentation(activityItems[0], 1.0);
}
- (void)performActivity
{
[[UIPasteboard generalPasteboard] setData:self.imageJPEGData forPasteboardType:(id)kUTTypeJPEG];
[self activityDidFinish:YES];
}
#end
And then I excluded the native copy activity:
PhotoActivityCopy *copyActivity = [[PhotoActivityCopy alloc] init];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:#[chosenImage] applicationActivities:#[copyActivity]];
activityViewController.excludedActivityTypes = #[UIActivityTypeCopyToPasteboard];

How to display multiselected images in iOS

I am making an app for iPhone and want to give users the ability to multiselect images from their photo-library. I already have a working code for user to select four images at a time.
But I can't select 1 or 2 or 3 images at a time. I want to select the 1 or 2 or 3 images at a time.
This is my code. I have struggled for 3 days without finding a solution. Please help me anybody.
Thanks in advance.............
-(void)choosePhotoFromExistingImages
{
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initImagePicker];
elcPicker.maximumImagesCount = 4;
elcPicker.returnsOriginalImage = NO; //Only return the fullScreenImage, not the fullResolutionImage
elcPicker.imagePickerDelegate = self;
[self presentViewController:elcPicker animated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self.navigationController dismissViewControllerAnimated: YES completion: nil];
}
- (void)displayPickerForGroup:(ALAssetsGroup *)group
{
ELCAssetTablePicker *tablePicker = [[ELCAssetTablePicker alloc] initWithStyle:UITableViewStylePlain];
tablePicker.singleSelection = YES;
tablePicker.immediateReturn = YES;
ELCImagePickerController *elcPicker = [[ELCImagePickerController alloc] initWithRootViewController:tablePicker];
elcPicker.maximumImagesCount = 0;
elcPicker.imagePickerDelegate = self;
elcPicker.returnsOriginalImage = NO; //Only return the fullScreenImage, not the fullResolutionImage
tablePicker.parent = elcPicker;
// Move me
tablePicker.assetGroup = group;
[tablePicker.assetGroup setAssetsFilter:[ALAssetsFilter allAssets]];
[self presentViewController:elcPicker animated:YES completion:nil];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
return YES;
}
else
{
return toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}
}
#pragma mark ELCImagePickerControllerDelegate Methods
- (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
CGRect workingFrame = _scrollView.frame;
workingFrame.origin.x = 0;
NSMutableArray *images = [NSMutableArray arrayWithCapacity:[info count]];
for (NSDictionary *dict in info)
{
UIImage *image = [dict objectForKey:UIImagePickerControllerOriginalImage];
[images addObject:image];
UIImageView *imageview = [[UIImageView alloc] initWithImage:image];
[imageview setContentMode:UIViewContentModeScaleAspectFit];
imageview.frame = workingFrame;
[self.view addSubview:imageview ];
self.chosenImages = images;
}
UIImageView *image1=[[UIImageView alloc]initWithFrame:CGRectMake(10, 240, 40, 40)];
image1.image=[images objectAtIndex:0];
[self.view addSubview:image1];
UIImageView *image2=[[UIImageView alloc]initWithFrame:CGRectMake(60, 240, 40, 40)];
image2.image=[images objectAtIndex:1];
[self.view addSubview:image2];
UIImageView *image3=[[UIImageView alloc]initWithFrame:CGRectMake(120, 240, 40, 40)];
image3.image=[images objectAtIndex:2];
[self.view addSubview:image3];
UIImageView *image4=[[UIImageView alloc]initWithFrame:CGRectMake(180, 240, 40, 40)];
image4.image=[images objectAtIndex:3];
[self.view addSubview:image4];
}
- (void)elcImagePickerControllerDidCancel:(ELCImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Here is the link for the Tutorial. Its works fine in my project.Try this
Hope its useful for you.
Check your code in - (void)elcImagePickerController:(ELCImagePickerController *)picker didFinishPickingMediaWithInfo:(NSArray *)info
For example, you create array with length of 2, but in code below you try to get image3.image=[images objectAtIndex:2]; and image4.image=[images objectAtIndex:3];. It's not a surprise that your code throws exception.
Good luck!

Load a ViewController code from a xib project imported to a storyboard project.

I have been experimenting with some code in a sample project that uses xibs. In that project the below method takes a photo that was picked via UIImagePickerController and displays another VC modally initializing its scrollview with the image.
This works fine in the xib project but now that im integrating it into a storyboard project this section throws an exception:
SSPhotoCropperViewController *photoCropper =
[[SSPhotoCropperViewController alloc] initWithPhoto:nonRawImage
delegate:self
uiMode:SSPCUIModePresentedAsModalViewController
showsInfoButton:YES];
The error is:
'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/24FB2532-BB1D-4573-8551-386FAA154022/BubbleBoss.app> (loaded)' with name 'SSPhotoCropperViewController''
Which seems to be saying that its looking for the xib file that isnt there. I have created a mimicked storyboard version of the xib and hooked up all my actions and outlets the same.
How do I display a storyboard VC in the below method, set the scrollview photo to nonRawImage, pass it the min and max zoom as is done below?
Problem Method:
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
[self dismissViewControllerAnimated:NO completion:nil];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
UIImage *image = info[UIImagePickerControllerOriginalImage];
UIImage *nonRawImage=[self scaleAndRotateImage:image];
SSPhotoCropperViewController *photoCropper =
[[SSPhotoCropperViewController alloc] initWithPhoto:nonRawImage
delegate:self
uiMode:SSPCUIModePresentedAsModalViewController
showsInfoButton:YES];
[photoCropper setMinZoomScale:0.25f];
[photoCropper setMaxZoomScale:3.00f];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:photoCropper];
[self presentViewController:nc animated:YES completion:nil];
// photoPreviewImageView.image = image;
if (_newMedia)
UIImageWriteToSavedPhotosAlbum(image,
self,
#selector(image:finishedSavingWithError:contextInfo:),
nil);
}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}
}
Code from SSPhotoCropperViewController.m
- (id) initWithPhoto:(UIImage *)aPhoto
delegate:(id<SSPhotoCropperDelegate>)aDelegate
{
return [self initWithPhoto:aPhoto
delegate:aDelegate
uiMode:SSPCUIModePresentedAsModalViewController
showsInfoButton:YES];
}
- (id) initWithPhoto:(UIImage *)aPhoto
delegate:(id<SSPhotoCropperDelegate>)aDelegate
uiMode:(SSPhotoCropperUIMode)uiMode
showsInfoButton:(BOOL)showsInfoButton
{
if (!(self = [super initWithNibName:#"SSPhotoCropperViewController" bundle:nil])) {
return self;
}
self.photo = aPhoto;
self.delegate = aDelegate;
_uiMode = uiMode;
_showsInfoButton = showsInfoButton;
self.minZoomScale = 0.5f;
self.maxZoomScale = 3.0f;
self.infoMessageTitle = #"In order to crop the photo";
self.infoMessageBody = #"Use two of your fingers to zoom in and out the photo and drag the"
#" green window to crop any part of the photo you would like to use.";
self.photoCropperTitle = #"Crop Photo";
return self;
}
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.photo = nil;
self.delegate = nil;
}
return self;
}
- (void) didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
}
- (IBAction) infoButtonTapped:(id)sender
{
UIAlertView *av = [[UIAlertView alloc] initWithTitle:self.infoMessageTitle
message:self.infoMessageBody
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[av show];
}
#pragma -
#pragma mark - View lifecycle
- (void) viewDidLoad
{
[super viewDidLoad];
//
// setup view ui
//
UIBarButtonItem *bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:#selector(saveAndClose:)];
self.navigationItem.rightBarButtonItem = bi;
if (_uiMode == SSPCUIModePresentedAsModalViewController) {
bi = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:#selector(cancelAndClose:)];
self.navigationItem.leftBarButtonItem = bi;
}
if (!_showsInfoButton) {
[self.infoButton setHidden:YES];
}
self.title = self.photoCropperTitle;
//
// photo cropper ui stuff
//
[self setScrollViewBackground];
[self.scrollView setMinimumZoomScale:self.minZoomScale];
[self.scrollView setMaximumZoomScale:self.maxZoomScale];
[self.cropRectangleButton addTarget:self
action:#selector(imageTouch:withEvent:)
forControlEvents:UIControlEventTouchDown];
[self.cropRectangleButton addTarget:self
action:#selector(imageMoved:withEvent:)
forControlEvents:UIControlEventTouchDragInside];
if (self.photo != nil) {
[self loadPhoto];
}
}
- (void) viewDidUnload
{
[super viewDidUnload];
}
- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}
#pragma -
#pragma UIScrollViewDelegate Methods
- (UIView *) viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return self.imageView;
}
#pragma -
#pragma Private Methods
- (void) loadPhoto
{
if (self.photo == nil) {
return;
}
CGFloat w = self.photo.size.width;
CGFloat h = self.photo.size.height;
CGRect imageViewFrame = CGRectMake(0.0f, 0.0f, roundf(w / 2.0f), roundf(h / 2.0f));
self.scrollView.contentSize = imageViewFrame.size;
UIImageView *iv = [[UIImageView alloc] initWithFrame:imageViewFrame];
iv.image = self.photo;
[self.scrollView addSubview:iv];
self.imageView = iv;
}
Ok ive got the method call changed to
SSPhotoCropperViewController *photoCropper =
[[SSPhotoCropperViewController alloc] initWithPhoto:photo
delegate:self
uiMode:SSPCUIModePresentedAsModalViewController
showsInfoButton:YES];
[photoCropper setMinZoomScale:0.25f];
[photoCropper setMaxZoomScale:3.00f];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:photoCropper];
But Im not sure what to do with the below:
- (id) initWithPhoto:(UIImage *)aPhoto
delegate:(id<SSPhotoCropperDelegate>)aDelegate
uiMode:(SSPhotoCropperUIMode)uiMode
showsInfoButton:(BOOL)showsInfoButton
{
if (!(self = [super initWithNibName:#"SSPhotoCropperViewController" bundle:nil])) {
return self;
}
self.photo = aPhoto;
self.delegate = aDelegate;
_uiMode = uiMode;
_showsInfoButton = showsInfoButton;
self.minZoomScale = 0.5f;
self.maxZoomScale = 3.0f;
self.infoMessageTitle = #"In order to crop the photo";
self.infoMessageBody = #"Use two of your fingers to zoom in and out the photo and drag the"
#" green window to crop any part of the photo you would like to use.";
self.photoCropperTitle = #"Crop Photo";
return self;
}
- (id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.photo = nil;
self.delegate = nil;
}
return self;
}
You should give your view controller an identifier within the storyboard, then instantiate it as follows:
YourViewControllerClass *viewController =
[[UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil]
instantiateViewControllerWithIdentifier:#"ViewController"];
The identifier can be set using Storyboard ID from within the Identity Inspector.
Make sure you set the SSPhotoCropperViewController's Identifier in the storyboard to SSPhotoCropperViewController.
Change your method:
- (id) initWithPhoto:(UIImage *)aPhoto
delegate:(id<SSPhotoCropperDelegate>)aDelegate
uiMode:(SSPhotoCropperUIMode)uiMode
showsInfoButton:(BOOL)showsInfoButton
{
//if (!(self = [super initWithNibName:#"SSPhotoCropperViewController" bundle:nil])) {
if (!(self = [[UIStoryboard storyboardWithName:#"YourStoryBoardName" bundle:nil]
instantiateViewControllerWithIdentifier:#"SSPhotoCropperViewController"])) {
return self;
}
self.photo = aPhoto;
self.delegate = aDelegate;
_uiMode = uiMode;
_showsInfoButton = showsInfoButton;
self.minZoomScale = 0.5f;
self.maxZoomScale = 3.0f;
self.infoMessageTitle = #"In order to crop the photo";
self.infoMessageBody = #"Use two of your fingers to zoom in and out the photo and drag the"
#" green window to crop any part of the photo you would like to use.";
self.photoCropperTitle = #"Crop Photo";
return self;
}

Sorting a Picture to a Specific Place in the app

I want it to flow like this I'm doing it tons of times and dosent work.
User pushes the photo button in the app and takes picture.
After taking the picture users has to input detail. sorts options comes out where user can pick 8 different default genre's, and user pushes save.
It goes back to the Home Screen and the User can see the 8 different genre in button & when pushed pictures comes out as a coverflow(flow cover) that is saved in the app. I want to make it work like the above but dosent work.
My Code is until now is:
#implementation ViewController
-(IBAction)TakePhoto {
picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
[picker setSourceType: UIImagePickerControllerSourceTypeCamera ];
[self presentViewController:picker animated:YES completion:NULL];
}
-(IBAction)ChooseExisting{
picker2 = [[UIImagePickerController alloc]init];
picker2.delegate = self;
[picker2 setSourceType: UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker2 animated:YES completion:NULL];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:
(NSDictionary *) info {
image = [info objectForKey:UIImagePickerControllerOriginalImage] ;
[imageview setImage:image];
[self dismissViewControllerAnimated:YES completion:NO];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:NULL];
}
#end
#implementation CVCLCoverFlowLayout
-(NSInteger)count {
return [self.collectionView numberOfItemsInSection:0 ];
}
-(CGSize)collectionViewContentSize{
CGSize size = self.collectionView.bounds.size;
size.width = self.count * self.cellInterval;
return size;
}
You are not saving the image you clicked in the delegate function .and when you want to use the saved image then you need to write down the code for same .:
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:
(NSDictionary *) info {
image = [info objectForKey:UIImagePickerControllerOriginalImage] ;
[imageview setImage:image];
/ save the image to local storage of your application /
[self dismissViewControllerAnimated:YES completion:NO];
}
You can check the code for same over :
http://dcraziee.wordpress.com/2013/05/20/how-to-save-and-get-image-from-cache-directory/
Please share the blog if you like it.

Resources