diff --git a/Classes/JPImagePickerController.h b/Classes/JPImagePickerController.h new file mode 100644 index 0000000..ed5e427 --- /dev/null +++ b/Classes/JPImagePickerController.h @@ -0,0 +1,195 @@ +// +// JPImagePickerController.h +// JPImagePickerController +// +// Created by Jeena on 11.11.09. +// Copyright 2009 Jeena Paradies. +// Licence: MIT-Licence +// + +#import +#import "JPImagePickerOverviewController.h" + +@class JPImagePickerController, JPImagePickerOverviewController; + +/*! + @enum JPImagePickerControllerThumbnailSize + @abstract Specifies the thumbnail width and height. + @constant kJPImagePickerControllerThumbnailSizeWidth Thumbnail width 75 px. + @constant kJPImagePickerControllerThumbnailSizeHeight Thumbnail height 75 px. + */ +enum JPImagePickerControllerThumbnailSize { + kJPImagePickerControllerThumbnailSizeWidth = 75, + kJPImagePickerControllerThumbnailSizeHeight = 75 +}; + +/*! + @enum JPImagePickerControllerPreviewImageSize + @abstract Specifies the preview image width and height. + @constant kJPImagePickerControllerPreviewImageSizeWidth Preview image width 320 px. + @constant kJPImagePickerControllerPreviewImageSizeHeight Preview image height 420 px. + */ +enum JPImagePickerControllerPreviewImageSize { + kJPImagePickerControllerPreviewImageSizeWidth = 320, + kJPImagePickerControllerPreviewImageSizeHeight = 420 +}; + +#pragma mark - + +/*! + @protocol JPImagePickerControllerDelegate + @abstract Delegate protocol for the JPImagePickerController + @discussion You have to implement this delegate in order to + use the JPImagePickerController. This delegate is responsible + for dismissing the picker on cancel or finished picking. + */ + +@protocol JPImagePickerControllerDelegate +@optional + +/*! + @method imagePickerDidCancel: + @abstract Called when picker did cancel + @discussion This method is called when the user canceled picking. + The delegate is responsible to dismiss the picker here. + @param picker The picker which called this method. + */ +- (void)imagePickerDidCancel:(JPImagePickerController *)picker; + +/*! + @method imagePicker:didFinishPickingWithImageNumber: + @abstract Called when the user picked a image. + @discussion This method is called when the user die finish picking. + The delegate is responsible to dismiss the picker here. + @param picker The picker which called this method. + @param imageNumber The number which image the user picked. + */ +- (void)imagePicker:(JPImagePickerController *)picker didFinishPickingWithImageNumber:(NSInteger)imageNumber; + +@end + + + +/*! + @protocol JPImagePickerControllerDataSource + @abstract The data source protocol for JPImagePickerController + @discussion The JPImagePickerController asks this data source for all + data which it wants to display. + */ + +@protocol JPImagePickerControllerDataSource +@optional + +/*! + @method numberOfImagesInImagePicker: + @abstract Should return the number of images. + @discussion This method should return the number of images which the + picker should display. + @param picker The picker which called this method. + */ +- (NSInteger)numberOfImagesInImagePicker:(JPImagePickerController *)picker; + +/*! + @method imagePicker:thumbnailForImageNumber: + @abstract Asks the data source for a thumbnail to insert in a particular location + the image picker. + @discussion This method should return a UIImage thumbnail for a image at the + image number position. The image should have the width of kJPImagePickerControllerThumbnailWidth + and height of kJPImagePickerControllerThumbnailWidth. If it is not that size the + image picker will resize it so it fits. + @param picker A picker-object requesting the thumbnail. + @param imageNumber A image number locating the image in the picker. + */ +- (UIImage *)imagePicker:(JPImagePickerController *)picker thumbnailForImageNumber:(NSInteger)imageNumber; + +/*! + @method imagePicker:imageForImageNumber: + @abstract Asks the data source for a image to show in a preview. + @discussion This method should return a UIImage image for the preview at + the image number position. The image should have the width of kJPImagePickerControllerPreviewImageWidth + and height of kJPImagePickerControllerPreviewImageWidth. If it is not that size the + image picker will resize it so it fits. + @param picker A picker-object requesting the image. + @param imageNumber A image number locating the image in the picker. + */ +- (UIImage *)imagePicker:(JPImagePickerController *)picker imageForImageNumber:(NSInteger)imageNumber; + +@end + +#pragma mark - + +/*! + @class JPImagePickerController + @abstract A image picker view controller. + @discussion A class which represents a image picker controller like apples UIImagePickerController + but lets you use a external dataSource for the images. + @updated 2009-11-14 + */ + +@interface JPImagePickerController : UIViewController { + IBOutlet UINavigationController *modalNavigationController; + JPImagePickerOverviewController *overviewController; + UIStatusBarStyle originalStatusBarStyle; + id delegate; + id dataSource; + NSString *imagePickerTitle; +} + +/*! + @property modalNavigationController + @abstract The additional navigation controller. + @discussion We need it to be able to view a navigation when the user + picks a image. + */ +@property (nonatomic, retain) IBOutlet UINavigationController *modalNavigationController; + +/*! + @property overviewController + @abstract Controller for the scrollView. + @discussion This controller holds the scrollView with all the buttons which + represent the images. + */ +@property (nonatomic, retain) JPImagePickerOverviewController *overviewController; + +/*! + @property overviewController + @abstract Original StatusBarStyle at the beginning. + @discussion This property saves the UIStatusBarStyle at the beginning, so that + we'll be able to change it back when we dismiss the image picker. + */ +@property (nonatomic, readonly) UIStatusBarStyle originalStatusBarStyle; + +/*! + @property delegate + @abstract The image picker's delegate object. + @discussion The delegate receives notifications when the user picks an image, + or exits the picker interface. The delegate also decides when to dismiss + the picker interface, so you must provide a delegate to use a picker. + If this property is nil, the picker is dismissed immediately if you try + to show it. + */ +@property (nonatomic, retain) id delegate; + +/*! + @property dataSource + @abstract The data source for the picker view. + @discussion The data source must adopt the JPImagePickerControllerDataSource protocol + and implement the required methods to return the number of components and the + number of rows in each component. + */ +@property (nonatomic, retain) id dataSource; + +/*! + @property imagePickerTitle + @abstract The image picker title. + @discussion You can set the title for the image overview here. + */ +@property (nonatomic, retain) NSString *imagePickerTitle; + +/*! + @method cancelPicking: + @param sender The button which sends the action. + */ +- (void)cancelPicking:(id)sender; + +@end diff --git a/Classes/JPImagePickerController.m b/Classes/JPImagePickerController.m new file mode 100644 index 0000000..ab38781 --- /dev/null +++ b/Classes/JPImagePickerController.m @@ -0,0 +1,103 @@ +// +// JPImagePickerController.m +// JPImagePickerController +// +// Created by Jeena on 11.11.09. +// Copyright 2009 Jeena Paradies. +// Licence: MIT-Licence +// + +#import "JPImagePickerController.h" + + +@implementation JPImagePickerController + +@synthesize overviewController, modalNavigationController, delegate, dataSource, originalStatusBarStyle; + +/* + // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. +- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { + if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) { + // Custom initialization + } + return self; +} +*/ + + +// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. +- (void)viewDidLoad { + [super viewDidLoad]; + + originalStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; + [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:YES]; + + overviewController = [[JPImagePickerOverviewController alloc] initWithImagePickerController:self]; + modalNavigationController = [[UINavigationController alloc] initWithRootViewController:overviewController]; + modalNavigationController.view.frame = self.view.bounds; + modalNavigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent; + modalNavigationController.navigationBar.translucent = YES; + [self.view addSubview:modalNavigationController.view]; +} + +- (void)setImagePickerTitle:(NSString *)newTitle { + imagePickerTitle = newTitle; + [overviewController setImagePickerTitle:newTitle]; +} + +- (NSString *)imagePickerTitle { + return imagePickerTitle; +} + +-(void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + if (delegate == nil) { + [self.navigationController dismissModalViewControllerAnimated:YES]; + } + [modalNavigationController viewWillAppear:animated]; +} + +-(void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + [modalNavigationController viewWillDisappear:animated]; +} +-(void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; + [modalNavigationController viewDidAppear:animated]; +} +-(void)viewDidDisappear:(BOOL)animated { + [super viewDidDisappear:animated]; + [modalNavigationController viewDidDisappear:animated]; +} + +/* +// Override to allow orientations other than the default portrait orientation. +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + // Return YES for supported orientations + return (interfaceOrientation == UIInterfaceOrientationPortrait); +} +*/ + +- (void)cancelPicking:(id)sender { + [delegate imagePickerDidCancel:self]; +} + +- (void)didReceiveMemoryWarning { + // Releases the view if it doesn't have a superview. + [super didReceiveMemoryWarning]; + + // Release any cached data, images, etc that aren't in use. +} + +- (void)viewDidUnload { + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + + +- (void)dealloc { + [super dealloc]; +} + + +@end diff --git a/Classes/JPImagePickerDetailController.h b/Classes/JPImagePickerDetailController.h new file mode 100644 index 0000000..b96fd67 --- /dev/null +++ b/Classes/JPImagePickerDetailController.h @@ -0,0 +1,35 @@ +// +// JPImagePickerDetailController.h +// JPImagePickerController +// +// Created by Jeena on 11.11.09. +// Copyright 2009 Jeena Paradies. +// Licence: MIT-Licence +// + +#import +#import "JPImagePickerController.h" +#import "JPImagePickerOverviewController.h" +#import "UIImageResizing.h" + +@protocol JPImagePickerControllerDelegate; +@protocol JPImagePickerControllerDataSource; +@class JPImagePickerOverviewController; + +@interface JPImagePickerDetailController : UIViewController { + JPImagePickerOverviewController *overviewController; + IBOutlet UIImageView *previewImageView; + NSInteger imageNumber; + UIStatusBarStyle originalStatusBarStyle; +} + +@property (nonatomic, retain) IBOutlet UIImageView *previewImageView; +@property (nonatomic, retain, readonly) JPImagePickerOverviewController *overviewController; +@property (nonatomic) NSInteger imageNumber; + +- (id)initWithOverviewController:(JPImagePickerOverviewController *)newOverviewController; +- (void)prepareForImageNumber:(NSInteger)newImageNumber; +- (IBAction)cancelPreview:(id)sender; +- (IBAction)finishedPicking:(id)sender; + +@end diff --git a/Classes/JPImagePickerDetailController.m b/Classes/JPImagePickerDetailController.m new file mode 100644 index 0000000..a3dd004 --- /dev/null +++ b/Classes/JPImagePickerDetailController.m @@ -0,0 +1,103 @@ +// +// JPImagePickerDetailController.m +// JPImagePickerController +// +// Created by Jeena on 11.11.09. +// Copyright 2009 Jeena Paradies. +// Licence: MIT-Licence +// + +#import "JPImagePickerDetailController.h" + + +@implementation JPImagePickerDetailController + +@synthesize previewImageView, overviewController, imageNumber; + +- (id)initWithOverviewController:(JPImagePickerOverviewController *)newOverviewController { + if (self = [super initWithNibName:@"JPImagePickerDetailController" bundle:nil]) { + // Custom initialization + overviewController = newOverviewController; + imageNumber = -1; + } + return self; +} + + +// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. +- (void)viewDidLoad { + [super viewDidLoad]; +} + + +- (void)viewWillAppear:(BOOL)animated { + originalStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; + [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque animated:YES]; + [super viewWillAppear:animated]; + [self.navigationController setNavigationBarHidden:YES animated:YES]; + [self prepareForImageNumber:imageNumber]; +} + +/* +- (void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; +} +*/ +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + [self.navigationController setNavigationBarHidden:NO animated:YES]; +} + +/* + - (void)viewDidDisappear:(BOOL)animated { + [super viewDidDisappear:animated]; + } +*/ + +/* +// Override to allow orientations other than the default portrait orientation. +- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + // Return YES for supported orientations + return (interfaceOrientation == UIInterfaceOrientationPortrait); +} +*/ + + +- (void)prepareForImageNumber:(NSInteger)newImageNumber { + imageNumber = newImageNumber; + previewImageView.image = [[overviewController.imagePickerController.dataSource + imagePicker:overviewController.imagePickerController + imageForImageNumber:imageNumber] + scaleToSize:CGSizeMake(kJPImagePickerControllerPreviewImageSizeHeight, kJPImagePickerControllerPreviewImageSizeHeight) + onlyIfNeeded:YES]; +} + +- (IBAction)cancelPreview:(id)sender { + [[UIApplication sharedApplication] setStatusBarStyle:originalStatusBarStyle animated:YES]; + [self.navigationController popViewControllerAnimated:YES]; +} + +- (IBAction)finishedPicking:(id)sender { + [[UIApplication sharedApplication] setStatusBarStyle:overviewController.imagePickerController.originalStatusBarStyle animated:YES]; + [overviewController.imagePickerController.delegate imagePicker:overviewController.imagePickerController didFinishPickingWithImageNumber:imageNumber]; +} + +- (void)didReceiveMemoryWarning { + // Releases the view if it doesn't have a superview. + [super didReceiveMemoryWarning]; + + // Release any cached data, images, etc that aren't in use. +} + +- (void)viewDidUnload { + // Release any retained subviews of the main view. + // e.g. self.myOutlet = nil; +} + + +- (void)dealloc { + [super dealloc]; +} + + +@end diff --git a/Classes/JPImagePickerDetailController.xib b/Classes/JPImagePickerDetailController.xib new file mode 100644 index 0000000..2528a5f --- /dev/null +++ b/Classes/JPImagePickerDetailController.xib @@ -0,0 +1,488 @@ + + + + 784 + 10C540 + 740 + 1038.25 + 458.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 62 + + + YES + + + + YES + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + YES + + YES + + + YES + + + + YES + + IBFilesOwner + + + IBFirstResponder + + + + 292 + + YES + + + 266 + {{0, 436}, {320, 44}} + + NO + NO + 2 + + YES + + 1 + + 1 + + + + 5 + + + Choose + 2 + + + + + + + 274 + {320, 436} + + NO + 4 + NO + + + {320, 480} + + + 2 + MCAwLjAwNzg0MzEzNzcxOSAwLjAwNzg0MzEzNzcxOQA + + NO + + 1 + + + + + + YES + + + view + + + + 10 + + + + previewImageView + + + + 11 + + + + cancelPreview: + + + + 12 + + + + finishedPicking: + + + + 13 + + + + + YES + + 0 + + + + + + -1 + + + File's Owner + + + -2 + + + + + 4 + + + YES + + + + + Preview + + + 5 + + + + + 6 + + + YES + + + + + + + + 7 + + + + + 8 + + + + + 9 + + + + + + + YES + + YES + -1.CustomClassName + -2.CustomClassName + 4.IBEditorWindowLastContentRect + 4.IBPluginDependency + 5.IBPluginDependency + 6.IBPluginDependency + 7.IBPluginDependency + 8.IBPluginDependency + 9.IBPluginDependency + + + YES + JPImagePickerDetailController + UIResponder + {{179, 638}, {320, 480}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + YES + + + YES + + + + + YES + + + YES + + + + 13 + + + + YES + + JPImagePickerDetailController + UIViewController + + YES + + YES + cancelPreview: + finishedPicking: + + + YES + id + id + + + + previewImageView + UIImageView + + + IBProjectSource + Classes/JPImagePickerDetailController.h + + + + + YES + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSError.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFileManager.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueObserving.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyedArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSNetServices.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObject.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSPort.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSRunLoop.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSStream.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSThread.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURL.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLConnection.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSXMLParser.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIAccessibility.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UINibLoading.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIResponder.h + + + + UIBarButtonItem + UIBarItem + + IBFrameworkSource + UIKit.framework/Headers/UIBarButtonItem.h + + + + UIBarItem + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIBarItem.h + + + + UIImageView + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIImageView.h + + + + UIResponder + NSObject + + + + UISearchBar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UISearchBar.h + + + + UISearchDisplayController + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UISearchDisplayController.h + + + + UIToolbar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIToolbar.h + + + + UIView + + IBFrameworkSource + UIKit.framework/Headers/UITextField.h + + + + UIView + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIView.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UINavigationController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UITabBarController.h + + + + UIViewController + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIViewController.h + + + + + 0 + + com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 + + + YES + ../Emoticard.xcodeproj + 3 + 3.1 + + diff --git a/Classes/JPImagePickerOverviewController.h b/Classes/JPImagePickerOverviewController.h new file mode 100644 index 0000000..4a21667 --- /dev/null +++ b/Classes/JPImagePickerOverviewController.h @@ -0,0 +1,35 @@ +// +// JPImagePickerOverviewController.h +// JPImagePickerController +// +// Created by Jeena on 11.11.09. +// Copyright 2009 Jeena Paradies. +// Licence: MIT-Licence +// + +#import +#import "JPImagePickerController.h" +#import "JPImagePickerDetailController.h" +#import "UIImageResizing.h" + +@class JPImagePickerController, JPImagePickerDetailController; +@protocol JPImagePickerControllerDelegate, JPImagePickerControllerDataSource; + +@interface JPImagePickerOverviewController : UIViewController { + JPImagePickerController *imagePickerController; + JPImagePickerDetailController *detailController; + IBOutlet UIScrollView *scrollView; +} + +@property (nonatomic, retain, readonly) JPImagePickerController *imagePickerController; +@property (nonatomic, retain) JPImagePickerDetailController *detailController; +@property (nonatomic, retain) IBOutlet UIScrollView *scrollView; + + +- (id)initWithImagePickerController:(JPImagePickerController *)newImagePickerController; +- (void)setImagePickerTitle:(NSString *)newTitle; +- (NSString *)imagePickerTitle; +- (IBAction)cancelPicking:(id)sender; +- (void)buttonTouched:(UIButton *)sender; + +@end diff --git a/Classes/JPImagePickerOverviewController.m b/Classes/JPImagePickerOverviewController.m new file mode 100644 index 0000000..c097eb7 --- /dev/null +++ b/Classes/JPImagePickerOverviewController.m @@ -0,0 +1,128 @@ +// +// JPImagePickerOverviewController.m +// JPImagePickerController +// +// Created by Jeena on 11.11.09. +// Copyright 2009 Jeena Paradies. +// Licence: MIT-Licence +// + +#import "JPImagePickerOverviewController.h" + + +@implementation JPImagePickerOverviewController + +@synthesize imagePickerController, detailController, scrollView; + +#define PADDING_TOP 44 +#define PADDING 4 +#define THUMBNAIL_COLS 4 + +- (id)initWithImagePickerController:(JPImagePickerController *)newImagePickerController { + if (self = [super initWithNibName:@"JPImagePickerOverviewController" bundle:nil]) { + // Custom initialization + imagePickerController = newImagePickerController; + } + return self; +} + + +// Implement viewDidLoad to do additional setup after loading the view, typically from a nib. +- (void)viewDidLoad { + [super viewDidLoad]; + + [self setImagePickerTitle:imagePickerController.imagePickerTitle]; + + UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel + target:self + action:@selector(cancelPicking:)]; + self.navigationItem.rightBarButtonItem = cancelButton; + [cancelButton release]; + + + UIButton *button; + UIImage *thumbnail; + int images_count = [imagePickerController.dataSource numberOfImagesInImagePicker:imagePickerController]; + + for (int i=0; i + + + 784 + 10C540 + 740 + 1038.25 + 458.00 + + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + 62 + + + YES + + + + YES + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + YES + + YES + + + YES + + + + YES + + IBFilesOwner + + + IBFirstResponder + + + + 264 + + YES + + + 274 + {320, 480} + + YES + YES + NO + + + {320, 480} + + + 3 + MQA + + 2 + + + + 1 + + + + + + YES + + + view + + + + 3 + + + + scrollView + + + + 5 + + + + + YES + + 0 + + + + + + 1 + + + YES + + + + ScrollView + + + -1 + + + File's Owner + + + -2 + + + + + 4 + + + + + + + YES + + YES + -1.CustomClassName + -2.CustomClassName + 1.IBEditorWindowLastContentRect + 1.IBPluginDependency + 4.IBPluginDependency + + + YES + JPImagePickerOverviewController + UIResponder + {{556, 412}, {320, 480}} + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + + + + YES + + + YES + + + + + YES + + + YES + + + + 5 + + + + YES + + JPImagePickerOverviewController + UIViewController + + YES + + YES + buttonTouched: + cancelPicking: + + + YES + UIButton + id + + + + scrollView + UIScrollView + + + IBProjectSource + Classes/JPImagePickerOverviewController.h + + + + + YES + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSError.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSFileManager.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueCoding.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyValueObserving.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSKeyedArchiver.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSNetServices.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSObject.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSPort.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSRunLoop.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSStream.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSThread.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURL.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSURLConnection.h + + + + NSObject + + IBFrameworkSource + Foundation.framework/Headers/NSXMLParser.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIAccessibility.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UINibLoading.h + + + + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UIResponder.h + + + + UIButton + UIControl + + IBFrameworkSource + UIKit.framework/Headers/UIButton.h + + + + UIControl + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIControl.h + + + + UIResponder + NSObject + + + + UIScrollView + UIView + + IBFrameworkSource + UIKit.framework/Headers/UIScrollView.h + + + + UISearchBar + UIView + + IBFrameworkSource + UIKit.framework/Headers/UISearchBar.h + + + + UISearchDisplayController + NSObject + + IBFrameworkSource + UIKit.framework/Headers/UISearchDisplayController.h + + + + UIView + + IBFrameworkSource + UIKit.framework/Headers/UITextField.h + + + + UIView + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIView.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UINavigationController.h + + + + UIViewController + + IBFrameworkSource + UIKit.framework/Headers/UITabBarController.h + + + + UIViewController + UIResponder + + IBFrameworkSource + UIKit.framework/Headers/UIViewController.h + + + + + 0 + + com.apple.InterfaceBuilder.CocoaTouchPlugin.InterfaceBuilder3 + + + YES + ../Emoticard.xcodeproj + 3 + 3.1 + + diff --git a/Classes/UIImageResizing.h b/Classes/UIImageResizing.h new file mode 100644 index 0000000..b6ee266 --- /dev/null +++ b/Classes/UIImageResizing.h @@ -0,0 +1,27 @@ +// +// UIImageResizing.h +// JPImagePickerController +// +// Created by Jeena on 07.11.09. +// Copyright 2009 Jeena Paradies. +// Licence: MIT-Licence +// +// Most of this code is from http://stackoverflow.com/questions/603907/uiimage-resize-then-crop + +#import + + +@interface UIImage (Resize) + ++ (UIImage *)image:(UIImage *)sourceImage scaleAndCroppForSize:(CGSize)targetSize; +- (UIImage *)scaleAndCropToSize:(CGSize)newSize; +- (UIImage *)scaleAndCropToSize:(CGSize)targetSize onlyIfNeeded:(BOOL)onlyIfNeeded; + ++ (UIImage *)image:(UIImage *)image scaleToSize:(CGSize)newSize; +- (UIImage *)scaleToSize:(CGSize)newSize; +- (UIImage *)scaleToSize:(CGSize)targetSize onlyIfNeeded:(BOOL)onlyIfNeeded; + ++ (BOOL)image:(UIImage *)sourceImage needsToScale:(CGSize)targetSize; +- (BOOL)needsToScale:(CGSize)targetSize; + +@end diff --git a/Classes/UIImageResizing.m b/Classes/UIImageResizing.m new file mode 100644 index 0000000..4181454 --- /dev/null +++ b/Classes/UIImageResizing.m @@ -0,0 +1,150 @@ +// +// UIImageResizing.m +// JPImagePickerController +// +// Created by Jeena on 07.11.09. +// Copyright 2009 Jeena Paradies. +// Licence: MIT-Licence +// + +#import "UIImageResizing.h" + + +@implementation UIImage (Resizing) + ++ (UIImage *)image:(UIImage *)sourceImage scaleAndCroppForSize:(CGSize)targetSize { + + UIImage *newImage = nil; + CGSize imageSize = sourceImage.size; + CGFloat width = imageSize.width; + CGFloat height = imageSize.height; + CGFloat targetWidth = targetSize.width; + CGFloat targetHeight = targetSize.height; + CGFloat scaleFactor = 0.0; + CGFloat scaledWidth = targetWidth; + CGFloat scaledHeight = targetHeight; + CGPoint thumbnailPoint = CGPointMake(0.0,0.0); + + if (CGSizeEqualToSize(imageSize, targetSize) == NO) + { + CGFloat widthFactor = targetWidth / width; + CGFloat heightFactor = targetHeight / height; + + if (widthFactor >= heightFactor) { + scaleFactor = widthFactor; // scale to fit height + } else { + scaleFactor = heightFactor; // scale to fit width + } + + scaledWidth = width * scaleFactor; + scaledHeight = height * scaleFactor; + + // center the image + if (widthFactor >= heightFactor) { + thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5; + } else if (widthFactor < heightFactor) { + thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5; + } + } + + UIGraphicsBeginImageContext(targetSize); // this will crop + + CGRect thumbnailRect = CGRectZero; + thumbnailRect.origin = thumbnailPoint; + thumbnailRect.size.width = scaledWidth; + thumbnailRect.size.height = scaledHeight; + + [sourceImage drawInRect:thumbnailRect]; + + newImage = UIGraphicsGetImageFromCurrentImageContext(); + if(newImage == nil) + NSLog(@"could not scale image"); + + //pop the context to get back to the default + UIGraphicsEndImageContext(); + + return newImage; +} + +- (UIImage *)scaleAndCropToSize:(CGSize)targetSize { + return [UIImage image:self scaleAndCroppForSize:(CGSize)targetSize]; +} + +- (UIImage *)scaleAndCropToSize:(CGSize)targetSize onlyIfNeeded:(BOOL)onlyIfNeeded { + + UIImage *image; + + if (!onlyIfNeeded || [self needsToScale:targetSize]) { + image = [self scaleAndCropToSize:targetSize]; + } else { + image = self; + } + + return image; +} + ++ (UIImage *)image:(UIImage *)sourceImage scaleToSize:(CGSize)targetSize { + + CGFloat scaleFactor = 0.0; + CGFloat scaledWidth = targetSize.width; + CGFloat scaledHeight = targetSize.height; + + CGFloat widthFactor = targetSize.width / sourceImage.size.width; + CGFloat heightFactor = targetSize.height / sourceImage.size.height; + + if (widthFactor < heightFactor) { + scaleFactor = widthFactor; // scale to fit height + } else { + scaleFactor = heightFactor; // scale to fit width + } + + scaledWidth = sourceImage.size.width * scaleFactor; + scaledHeight = sourceImage.size.height * scaleFactor; + + CGSize propperSize = CGSizeMake(scaledWidth, scaledHeight); + + UIGraphicsBeginImageContext( propperSize ); + [sourceImage drawInRect:CGRectMake(0, 0, propperSize.width, propperSize.height)]; + UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + return newImage; +} + +- (UIImage *)scaleToSize:(CGSize)newSize { + return [UIImage image:self scaleToSize:newSize]; +} + +- (UIImage *)scaleToSize:(CGSize)targetSize onlyIfNeeded:(BOOL)onlyIfNeeded { + + UIImage *image; + + if (!onlyIfNeeded || [self needsToScale:targetSize]) { + image = [self scaleToSize:targetSize]; + } else { + image = self; + } + + return image; +} + ++ (BOOL)image:(UIImage *)sourceImage needsToScale:(CGSize)targetSize { + BOOL needsToScale = NO; + + if (sourceImage.size.width > targetSize.width) { + needsToScale = YES; + } + + if (sourceImage.size.height > targetSize.height) { + needsToScale = YES; + } + + return needsToScale; +} + +- (BOOL)needsToScale:(CGSize)targetSize { + return [UIImage image:self needsToScale:targetSize]; +} + + +@end diff --git a/Documentation/Classes/JPImagePickerController/index.html b/Documentation/Classes/JPImagePickerController/index.html new file mode 100644 index 0000000..46064ac --- /dev/null +++ b/Documentation/Classes/JPImagePickerController/index.html @@ -0,0 +1,188 @@ + + + JPImagePickerController + + + + + + + + +
+ +
+
+ +

JPImagePickerController

+

A image picker view controller. +

+

Superclass: UIViewController
+Declared In: JPImagePickerController.h
+

+
+
Discussion +

A class which represents a image picker controller like apples UIImagePickerController +but lets you use a external dataSource for the images. + +

Updated:
Saturday, November 14, 2009
+
+

+

Methods

+
+
-cancelPicking:
+
+
+
+ +

cancelPicking:

+

+
- (void)cancelPicking:(id)sender; 
+
+
Parameters
+
+
+
sender

The button which sends the action.

+
+
+

+

Properties

+
+
dataSource
+

The data source for the picker view. +

+
delegate
+

The image picker's delegate object. +

+
imagePickerTitle
+

The image picker title. +

+
modalNavigationController
+

The additional navigation controller. +

+
originalStatusBarStyle
+

Original StatusBarStyle at the beginning. +

+
overviewController
+

Controller for the scrollView. +

+
+
+ +

dataSource

+

The data source for the picker view. +

+

+
@property (
+    nonatomic,
+    retain) id<JPImagePickerControllerDataSource> dataSource; 
+
+
Discussion +

The data source must adopt the JPImagePickerControllerDataSource protocol +and implement the required methods to return the number of components and the +number of rows in each component. + +


+ +

delegate

+

The image picker's delegate object. +

+

+
@property (
+    nonatomic,
+    retain) id<JPImagePickerControllerDelegate> delegate; 
+
+
Discussion +

The delegate receives notifications when the user picks an image, +or exits the picker interface. The delegate also decides when to dismiss +the picker interface, so you must provide a delegate to use a picker. +If this property is nil, the picker is dismissed immediately if you try +to show it. + +


+ +

imagePickerTitle

+

The image picker title. +

+

+
@property (
+    nonatomic,
+    retain) NSString *imagePickerTitle; 
+
+
Discussion +

You can set the title for the image overview here. + +


+ +

modalNavigationController

+

The additional navigation controller. +

+

+
@property (
+    nonatomic,
+    retain) IBOutlet UINavigationController *modalNavigationController; 
+
+
Discussion +

We need it to be able to view a navigation when the user +picks a image. + +


+ +

originalStatusBarStyle

+

Original StatusBarStyle at the beginning. +

+

+
@property (
+    nonatomic,
+    readonly) UIStatusBarStyle originalStatusBarStyle; 
+
+
Discussion +

This property saves the UIStatusBarStyle at the beginning, so that +we'll be able to change it back when we dismiss the image picker. + +


+ +

overviewController

+

Controller for the scrollView. +

+

+
@property (
+    nonatomic,
+    retain) JPImagePickerOverviewController *overviewController; 
+
+
Discussion +

This controller holds the scrollView with all the buttons which +represent the images. + +

Last Updated: Saturday, November 14, 2009 +

diff --git a/Documentation/Classes/JPImagePickerController/toc.html b/Documentation/Classes/JPImagePickerController/toc.html new file mode 100644 index 0000000..32da805 --- /dev/null +++ b/Documentation/Classes/JPImagePickerController/toc.html @@ -0,0 +1,35 @@ + + + +Documentation for JPImagePickerController (JPImagePickerController.h) + + + + + + +
 

+ + + +
 Class:
  JPImagePickerController
+


Introduction

+

Methods

+
Instance Methods
+      -cancelPicking:
+

Properties

+ +      dataSource
+      delegate
+      imagePickerTitle
+      modalNavigationController
+      originalStatusBarStyle
+      overviewController
+

Other Reference


+      Header
+

Updated: Saturday, November 14, 2009

 

+

+ diff --git a/Documentation/Protocols/JPImagePickerControllerDataSource/index.html b/Documentation/Protocols/JPImagePickerControllerDataSource/index.html new file mode 100644 index 0000000..15a21ff --- /dev/null +++ b/Documentation/Protocols/JPImagePickerControllerDataSource/index.html @@ -0,0 +1,136 @@ + + + JPImagePickerControllerDataSource + + + + + + +
+ +
+ +
+
+ +

JPImagePickerControllerDataSource

+

The data source protocol for JPImagePickerController +

+

Extends Protocol: NSObject
+Declared In: JPImagePickerController.h
+

+
+
Discussion +

The JPImagePickerController asks this data source for all +data which it wants to display. + +



+

Methods

+
+
-imagePicker:imageForImageNumber:
+

Asks the data source for a image to show in a preview. +

+
-imagePicker:thumbnailForImageNumber:
+

Asks the data source for a thumbnail to insert in a particular location +the image picker. +

+
-numberOfImagesInImagePicker:
+

Should return the number of images. +

+
+
+ +

imagePicker:imageForImageNumber:

+

Asks the data source for a image to show in a preview. +

+

+
- (UIImage *)imagePicker:(JPImagePickerController *)picker 
+        imageForImageNumber:(NSInteger)imageNumber; 
+
+
Parameters
+
+
+
picker

A picker-object requesting the image.

+
imageNumber

A image number locating the image in the picker.

+
+
+
Discussion +

This method should return a UIImage image for the preview at +the image number position. The image should have the width of kJPImagePickerControllerPreviewImageWidth +and height of kJPImagePickerControllerPreviewImageWidth. If it is not that size the +image picker will resize it so it fits. + +


+ +

imagePicker:thumbnailForImageNumber:

+

Asks the data source for a thumbnail to insert in a particular location +the image picker. +

+

+
- (UIImage *)imagePicker:(JPImagePickerController *)picker 
+        thumbnailForImageNumber:(NSInteger)imageNumber; 
+
+
Parameters
+
+
+
picker

A picker-object requesting the thumbnail.

+
imageNumber

A image number locating the image in the picker.

+
+
+
Discussion +

This method should return a UIImage thumbnail for a image at the +image number position. The image should have the width of kJPImagePickerControllerThumbnailWidth +and height of kJPImagePickerControllerThumbnailWidth. If it is not that size the +image picker will resize it so it fits. + +


+ +

numberOfImagesInImagePicker:

+

Should return the number of images. +

+

+
- (NSInteger)numberOfImagesInImagePicker:(JPImagePickerController *)picker; 
+
+
Parameters
+
+
+
picker

The picker which called this method.

+
+
+
Discussion +

This method should return the number of images which the +picker should display. + +

Last Updated: Saturday, November 14, 2009 +

diff --git a/Documentation/Protocols/JPImagePickerControllerDataSource/toc.html b/Documentation/Protocols/JPImagePickerControllerDataSource/toc.html new file mode 100644 index 0000000..c6fe482 --- /dev/null +++ b/Documentation/Protocols/JPImagePickerControllerDataSource/toc.html @@ -0,0 +1,29 @@ + + + +Documentation for JPImagePickerControllerDataSource (JPImagePickerController.h) + + + + + + +
 

+ + + +
 Protocol:
  JPImagePickerControllerDataSource
+


Introduction

+

Methods

+
Instance Methods
+      -imagePicker:‍imageForImageNumber:‍
+      -imagePicker:‍thumbnailForImageNumber:‍
+      -numberOfImagesInImagePicker:
+

Other Reference


+      Header
+

 

+

+ diff --git a/Documentation/Protocols/JPImagePickerControllerDelegate/index.html b/Documentation/Protocols/JPImagePickerControllerDelegate/index.html new file mode 100644 index 0000000..65ed027 --- /dev/null +++ b/Documentation/Protocols/JPImagePickerControllerDelegate/index.html @@ -0,0 +1,108 @@ + + + JPImagePickerControllerDelegate + + + + + + +
+ +
+ +
+
+ +

JPImagePickerControllerDelegate

+

Delegate protocol for the JPImagePickerController +

+

Extends Protocol: NSObject
+Declared In: JPImagePickerController.h
+

+
+
Discussion +

You have to implement this delegate in order to +use the JPImagePickerController. This delegate is responsible +for dismissing the picker on cancel or finished picking. + +



+

Methods

+
+
-imagePicker:didFinishPickingWithImageNumber:
+

Called when the user picked a image. +

+
-imagePickerDidCancel:
+

Called when picker did cancel +

+
+
+ +

imagePicker:didFinishPickingWithImageNumber:

+

Called when the user picked a image. +

+

+
- (void)imagePicker:(JPImagePickerController *)picker 
+        didFinishPickingWithImageNumber:(NSInteger)imageNumber; 
+
+
Parameters
+
+
+
picker

The picker which called this method.

+
imageNumber

The number which image the user picked.

+
+
+
Discussion +

This method is called when the user die finish picking. +The delegate is responsible to dismiss the picker here. + +


+ +

imagePickerDidCancel:

+

Called when picker did cancel +

+

+
- (void)imagePickerDidCancel:(JPImagePickerController *)picker; 
+
+
Parameters
+
+
+
picker

The picker which called this method.

+
+
+
Discussion +

This method is called when the user canceled picking. +The delegate is responsible to dismiss the picker here. + +

Last Updated: Saturday, November 14, 2009 +

diff --git a/Documentation/Protocols/JPImagePickerControllerDelegate/toc.html b/Documentation/Protocols/JPImagePickerControllerDelegate/toc.html new file mode 100644 index 0000000..58af0e2 --- /dev/null +++ b/Documentation/Protocols/JPImagePickerControllerDelegate/toc.html @@ -0,0 +1,28 @@ + + + +Documentation for JPImagePickerControllerDelegate (JPImagePickerController.h) + + + + + + +
 

+ + + +
 Protocol:
  JPImagePickerControllerDelegate
+


Introduction

+

Methods

+
Instance Methods
+      -imagePicker:‍didFinishPickingWithImageNumber:‍
+      -imagePickerDidCancel:
+

Other Reference


+      Header
+

 

+

+ diff --git a/Documentation/index.html b/Documentation/index.html new file mode 100644 index 0000000..1ebf105 --- /dev/null +++ b/Documentation/index.html @@ -0,0 +1,117 @@ + + + JPImagePickerController.h + + + + + + +
+ + +
+ +
+
+ +

JPImagePickerController.h

+

Use the links in the table of contents to the left to access the documentation.
+

+

+
+



+

Classes

+
+
JPImagePickerController
+

A image picker view controller. +

+
+ +

Protocols

+
+
JPImagePickerControllerDataSource
+

The data source protocol for JPImagePickerController +

+
JPImagePickerControllerDelegate
+

Delegate protocol for the JPImagePickerController +

+
+

+

Enumerated Types

+
+
JPImagePickerControllerPreviewImageSize
+

Specifies the preview image width and height. +

+
JPImagePickerControllerThumbnailSize
+

Specifies the thumbnail width and height. +

+
+
+ +

JPImagePickerControllerPreviewImageSize

+

Specifies the preview image width and height. +

+

+
enum JPImagePickerControllerPreviewImageSize { 
+    kJPImagePickerControllerPreviewImageSizeWidth = 320, 
+    kJPImagePickerControllerPreviewImageSizeHeight = 420 
+};  
+
+
Constants
+
+
+
kJPImagePickerControllerPreviewImageSizeWidth

Preview image width 320 px.

+
kJPImagePickerControllerPreviewImageSizeHeight

Preview image height 420 px.

+
+
+


+ +

JPImagePickerControllerThumbnailSize

+

Specifies the thumbnail width and height. +

+

+
enum JPImagePickerControllerThumbnailSize { 
+    kJPImagePickerControllerThumbnailSizeWidth = 75, 
+    kJPImagePickerControllerThumbnailSizeHeight = 75 
+};  
+
+
Constants
+ +

Last Updated: Saturday, November 14, 2009 +

diff --git a/Documentation/toc.html b/Documentation/toc.html new file mode 100644 index 0000000..e4d034f --- /dev/null +++ b/Documentation/toc.html @@ -0,0 +1,32 @@ + + + +Documentation for JPImagePickerController.h + + + + + + +
 

+ + + +
 Header:
  JPImagePickerController.h
+


Introduction

+

Enumerations +

+ +      JPImagePickerControllerPreviewImageSize
+      JPImagePickerControllerThumbnailSize
+

Classes

+      JPImagePickerController
+

Protocols

+      JPImagePickerControllerDataSource
+      JPImagePickerControllerDelegate
+

 

+

+