Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
// ELCImagePickerController.m
// ELCImagePickerDemo
//
// Created by ELC on 9/9/10.
// Copyright 2010 ELC Technologies. All rights reserved.
//
#import "ELCImagePickerController.h"
#import "ELCAsset.h"
#import "ELCAssetCell.h"
#import "ELCAssetTablePicker.h"
#import "ELCAlbumPickerController.h"
#import <CoreLocation/CoreLocation.h>
#import <MobileCoreServices/UTCoreTypes.h>
#import "ELCConsole.h"
@implementation ELCImagePickerController
- (id)initImagePicker
{
ELCAlbumPickerController *albumPicker = [[ELCAlbumPickerController alloc]
initWithStyle:UITableViewStylePlain];
- (id)initWithRootViewController:(UIViewController *)rootViewController
{
- (ELCAlbumPickerController *)albumPicker
{
return self.viewControllers[0];
}
- (void)setMediaTypes:(NSArray *)mediaTypes
{
self.albumPicker.mediaTypes = mediaTypes;
}
- (NSArray *)mediaTypes
{
return self.albumPicker.mediaTypes;
}
- (void)cancelImagePicker
{
if ([_imagePickerDelegate
respondsToSelector:@selector(elcImagePickerControllerDidCancel:)]) {
[_imagePickerDelegate
performSelector:@selector(elcImagePickerControllerDidCancel:) withObject:self];
}
}
- (void)selectedAssets:(NSArray *)assets
{
NSMutableArray *returnArray = [[NSMutableArray alloc] init];
if(assetRep != nil) {
if (_returnsImage) {
CGImageRef imgRef = nil;
//defaultRepresentation returns image as it appears in photo
picker, rotated and sized,
//so use UIImageOrientationUp when creating our image below.
UIImageOrientation orientation = UIImageOrientationUp;
if (_returnsOriginalImage) {
imgRef = [assetRep fullResolutionImage];
orientation = [assetRep orientation];
} else {
imgRef = [assetRep fullScreenImage];
}
UIImage *img = [UIImage imageWithCGImage:imgRef
scale:1.0f
orientation:orientation];
[workingDictionary setObject:img
forKey:UIImagePickerControllerOriginalImage];
}
[workingDictionary setObject:[[asset
valueForProperty:ALAssetPropertyURLs] valueForKey:[[[asset
valueForProperty:ALAssetPropertyURLs] allKeys] objectAtIndex:0]]
forKey:UIImagePickerControllerReferenceURL];
[returnArray addObject:workingDictionary];
}
}
if (_imagePickerDelegate != nil && [_imagePickerDelegate
respondsToSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo
:)]) {
[_imagePickerDelegate
performSelector:@selector(elcImagePickerController:didFinishPickingMediaWithInfo:)
withObject:self withObject:returnArray];
} else {
[self popToRootViewControllerAnimated:NO];
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:
(UIInterfaceOrientation)toInterfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return YES;
} else {
return toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}
}
- (BOOL)onOrder
{
return [[ELCConsole mainConsole] onOrder];
}
- (void)setOnOrder:(BOOL)onOrder
{
[[ELCConsole mainConsole] setOnOrder:onOrder];
}
@end