added protocols to one file
This commit is contained in:
parent
a4b90244db
commit
04c065d4d6
38 changed files with 2280 additions and 850 deletions
|
@ -7,22 +7,123 @@
|
|||
// Licence: MIT-Licence
|
||||
//
|
||||
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "JPImagePickerControllerDelegate.h"
|
||||
#import "JPImagePickerControllerDataSource.h"
|
||||
#import "JPImagePickerOverviewController.h"
|
||||
|
||||
@protocol JPImagePickerControllerDelegate;
|
||||
@protocol JPImagePickerControllerDataSource;
|
||||
@class JPImagePickerOverviewController;
|
||||
@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 <NSObject>
|
||||
@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 <NSObject>
|
||||
@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.
|
||||
@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-11
|
||||
@updated 2009-11-14
|
||||
*/
|
||||
|
||||
@interface JPImagePickerController : UIViewController {
|
||||
|
@ -92,4 +193,3 @@
|
|||
- (void)cancelPicking:(id)sender;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
//
|
||||
// JPImagePickerDataSourse.h
|
||||
// JPImagePickerController
|
||||
//
|
||||
// Created by Jeena on 11.11.09.
|
||||
// Copyright 2009 Jeena Paradies.
|
||||
// Licence: MIT-Licence
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "JPImagePickerController.h"
|
||||
|
||||
@class JPImagePickerController;
|
||||
|
||||
|
||||
/*!
|
||||
@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
|
||||
|
||||
/*!
|
||||
@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.
|
||||
@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.
|
||||
@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
|
|
@ -1,44 +0,0 @@
|
|||
//
|
||||
// JPImagePickerControllerDelegate.h
|
||||
// JPImagePickerController
|
||||
//
|
||||
// Created by Jeena on 07.11.09.
|
||||
// Copyright 2009 Jeena Paradies.
|
||||
// Licence: MIT-Licence
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "JPImagePickerController.h"
|
||||
|
||||
@class JPImagePickerController;
|
||||
|
||||
/*!
|
||||
@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
|
||||
|
||||
/*!
|
||||
@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
|
|
@ -8,7 +8,6 @@
|
|||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "JPImagePickerControllerDelegate.h"
|
||||
#import "JPImagePickerController.h"
|
||||
#import "JPImagePickerOverviewController.h"
|
||||
#import "UIImageResizing.h"
|
||||
|
|
|
@ -14,9 +14,6 @@
|
|||
|
||||
@synthesize previewImageView, overviewController, imageNumber;
|
||||
|
||||
#define PREVIEW_IMAGE_WIDTH 320
|
||||
#define PREVIEW_IMAGE_HEIGHT 420
|
||||
|
||||
- (id)initWithOverviewController:(JPImagePickerOverviewController *)newOverviewController {
|
||||
if (self = [super initWithNibName:@"JPImagePickerDetailController" bundle:nil]) {
|
||||
// Custom initialization
|
||||
|
@ -68,7 +65,11 @@
|
|||
|
||||
- (void)prepareForImageNumber:(NSInteger)newImageNumber {
|
||||
imageNumber = newImageNumber;
|
||||
previewImageView.image = [[overviewController.imagePickerController.dataSource imagePicker:overviewController.imagePickerController imageForImageNumber:imageNumber] scaleToSize:CGSizeMake(PREVIEW_IMAGE_WIDTH, PREVIEW_IMAGE_HEIGHT) onlyIfNeeded:YES];
|
||||
previewImageView.image = [[overviewController.imagePickerController.dataSource
|
||||
imagePicker:overviewController.imagePickerController
|
||||
imageForImageNumber:imageNumber]
|
||||
scaleToSize:CGSizeMake(kJPImagePickerControllerPreviewImageSizeHeight, kJPImagePickerControllerPreviewImageSizeHeight)
|
||||
onlyIfNeeded:YES];
|
||||
}
|
||||
|
||||
- (IBAction)cancelPreview:(id)sender {
|
||||
|
|
|
@ -9,14 +9,11 @@
|
|||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "JPImagePickerController.h"
|
||||
#import "JPImagePickerControllerDelegate.h"
|
||||
#import "JPImagePickerControllerDataSource.h"
|
||||
#import "JPImagePickerDetailController.h"
|
||||
#import "UIImageResizing.h"
|
||||
|
||||
@protocol JPImagePickerControllerDelegate;
|
||||
@protocol JPImagePickerControllerDataSource;
|
||||
@class JPImagePickerDetailController;
|
||||
@class JPImagePickerController, JPImagePickerDetailController;
|
||||
@protocol JPImagePickerControllerDelegate, JPImagePickerControllerDataSource;
|
||||
|
||||
@interface JPImagePickerOverviewController : UIViewController {
|
||||
JPImagePickerController *imagePickerController;
|
||||
|
|
|
@ -15,9 +15,7 @@
|
|||
@synthesize imagePickerController, detailController, scrollView;
|
||||
|
||||
#define PADDING_TOP 44
|
||||
#define COLS 4
|
||||
#define PADDING 4
|
||||
#define THUMBNAIL_SIZE 75
|
||||
#define THUMBNAIL_COLS 4
|
||||
|
||||
- (id)initWithImagePickerController:(JPImagePickerController *)newImagePickerController {
|
||||
|
@ -48,7 +46,7 @@
|
|||
|
||||
for (int i=0; i<images_count; i++) {
|
||||
thumbnail = [[imagePickerController.dataSource imagePicker:imagePickerController thumbnailForImageNumber:(NSInteger)i]
|
||||
scaleAndCropToSize:CGSizeMake(THUMBNAIL_SIZE, THUMBNAIL_SIZE)
|
||||
scaleAndCropToSize:CGSizeMake(kJPImagePickerControllerThumbnailSizeWidth, kJPImagePickerControllerThumbnailSizeHeight)
|
||||
onlyIfNeeded:NO];
|
||||
|
||||
button = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||
|
@ -57,10 +55,10 @@
|
|||
button.userInteractionEnabled = YES;
|
||||
[button addTarget:self action:@selector(buttonTouched:) forControlEvents:UIControlEventTouchUpInside];
|
||||
button.tag = i;
|
||||
button.frame = CGRectMake(THUMBNAIL_SIZE * (i % COLS) + PADDING * (i % COLS) + PADDING,
|
||||
THUMBNAIL_SIZE * (i / THUMBNAIL_COLS) + PADDING * (i / THUMBNAIL_COLS) + PADDING + PADDING_TOP,
|
||||
THUMBNAIL_SIZE,
|
||||
THUMBNAIL_SIZE);
|
||||
button.frame = CGRectMake(kJPImagePickerControllerThumbnailSizeWidth * (i % THUMBNAIL_COLS) + PADDING * (i % THUMBNAIL_COLS) + PADDING,
|
||||
kJPImagePickerControllerThumbnailSizeHeight * (i / THUMBNAIL_COLS) + PADDING * (i / THUMBNAIL_COLS) + PADDING + PADDING_TOP,
|
||||
kJPImagePickerControllerThumbnailSizeWidth,
|
||||
kJPImagePickerControllerThumbnailSizeHeight);
|
||||
|
||||
[scrollView addSubview:button];
|
||||
}
|
||||
|
@ -69,7 +67,7 @@
|
|||
if (((float)images_count / THUMBNAIL_COLS) - rows != 0) {
|
||||
rows++;
|
||||
}
|
||||
int height = THUMBNAIL_SIZE * rows + PADDING * rows + PADDING + PADDING_TOP;
|
||||
int height = kJPImagePickerControllerThumbnailSizeHeight * rows + PADDING * rows + PADDING + PADDING_TOP;
|
||||
|
||||
scrollView.contentSize = CGSizeMake(self.view.frame.size.width, height);
|
||||
scrollView.clipsToBounds = YES;
|
||||
|
|
|
@ -7,8 +7,7 @@
|
|||
// Licence: MIT-Licence
|
||||
//
|
||||
|
||||
#import "JPImagePickerControllerDelegate.h"
|
||||
#import "JPImagePickerControllerDataSource.h"
|
||||
#import "JPImagePickerController.h"
|
||||
|
||||
@interface RootViewController : UITableViewController <JPImagePickerControllerDelegate, JPImagePickerControllerDataSource> {
|
||||
NSInteger chosenImage;
|
||||
|
|
|
@ -134,7 +134,6 @@
|
|||
[imagePickerController release];
|
||||
|
||||
} else {
|
||||
|
||||
if (chosenImage == -1) {
|
||||
chosenImageView.image = [[UIImage imageNamed:@"noImageSelected.png"] scaleToSize:CGSizeMake(320, 480) onlyIfNeeded:YES];
|
||||
} else {
|
||||
|
|
Reference in a new issue