Skip to content

Commit 7b548b1

Browse files
committed
Update project settings
1 parent e5a7679 commit 7b548b1

File tree

2 files changed

+381
-0
lines changed

2 files changed

+381
-0
lines changed

.gitignore

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#########################
2+
# .gitignore file for Xcode4 / OS X Source projects
3+
#
4+
# NB: if you are storing "built" products, this WILL NOT WORK,
5+
# and you should use a different .gitignore (or none at all)
6+
# This file is for SOURCE projects, where there are many extra
7+
# files that we want to exclude
8+
#
9+
# For updates, see: http://stackoverflow.com/questions/49478/git-ignore-file-for-xcode-projects
10+
#########################
11+
12+
#####
13+
# OS X temporary files that should never be committed
14+
15+
.DS_Store
16+
*.swp
17+
*.lock
18+
profile
19+
20+
21+
####
22+
# Xcode temporary files that should never be committed
23+
#
24+
# NB: NIB/XIB files still exist even on Storyboard projects, so we want this...
25+
26+
*~.nib
27+
28+
29+
####
30+
# Xcode build files -
31+
#
32+
# NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "DerivedData"
33+
34+
DerivedData/
35+
36+
# NB: slash on the end, so we only remove the FOLDER, not any files that were badly named "build"
37+
38+
build/
39+
40+
41+
#####
42+
# Xcode private settings (window sizes, bookmarks, breakpoints, custom executables, smart groups)
43+
#
44+
# This is complicated:
45+
#
46+
# SOMETIMES you need to put this file in version control.
47+
# Apple designed it poorly - if you use "custom executables", they are
48+
# saved in this file.
49+
# 99% of projects do NOT use those, so they do NOT want to version control this file.
50+
# ..but if you're in the 1%, comment out the line "*.pbxuser"
51+
52+
*.pbxuser
53+
*.mode1v3
54+
*.mode2v3
55+
*.perspectivev3
56+
# NB: also, whitelist the default ones, some projects need to use these
57+
!default.pbxuser
58+
!default.mode1v3
59+
!default.mode2v3
60+
!default.perspectivev3
61+
62+
63+
####
64+
# Xcode 4 - semi-personal settings, often included in workspaces
65+
#
66+
# You can safely ignore the xcuserdata files - but do NOT ignore the files next to them
67+
#
68+
69+
xcuserdata
70+
71+
72+
####
73+
# XCode 4 workspaces - more detailed
74+
#
75+
# Workspaces are important! They are a core feature of Xcode - don't exclude them :)
76+
#
77+
# Workspace layout is quite spammy. For reference:
78+
#
79+
# (root)/
80+
# (project-name).xcodeproj/
81+
# project.pbxproj
82+
# project.xcworkspace/
83+
# contents.xcworkspacedata
84+
# xcuserdata/
85+
# (your name)/xcuserdatad/
86+
# xcuserdata/
87+
# (your name)/xcuserdatad/
88+
#
89+
#
90+
#
91+
# Xcode 4 workspaces - SHARED
92+
#
93+
# This is UNDOCUMENTED (google: "developer.apple.com xcshareddata" - 0 results
94+
# But if you're going to kill personal workspaces, at least keep the shared ones...
95+
#
96+
#
97+
!xcshareddata
98+
99+
100+
####
101+
# Xcode 4 - Deprecated classes
102+
#
103+
# Allegedly, if you manually "deprecate" your classes, they get moved here.
104+
#
105+
# We're using source-control, so this is a "feature" that we do not want!
106+
107+
*.moved-aside
108+
109+
110+
####
111+
# UNKNOWN: recommended by others, but I can't discover what these files are
112+
#
113+
# ...none. Everything is now explained.

FDTakeExample/FDTakeController.m

+268
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
//
2+
// FDTakeController.m
3+
// FDTakeExample
4+
//
5+
// Created by Will Entriken on 8/9/12.
6+
// Copyright (c) 2012 William Entriken. All rights reserved.
7+
//
8+
9+
#import "FDTakeController.h"
10+
11+
@interface FDTakeController() <UIActionSheetDelegate, UIAlertViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
12+
@property (strong, nonatomic) NSMutableArray *sources;
13+
@property (strong, nonatomic) NSMutableArray *buttonTitles;
14+
@property (strong, nonatomic) UIActionSheet *actionSheet;
15+
@property (strong, nonatomic) UIPopoverController *popover;
16+
17+
// Returns either optional view controll for presenting or main window.
18+
- (UIViewController*)presentingViewController;
19+
20+
@end
21+
22+
@implementation FDTakeController
23+
@synthesize sources = _sources;
24+
@synthesize buttonTitles = _buttonTitles;
25+
@synthesize actionSheet = _actionSheet;
26+
@synthesize imagePicker = _imagePicker;
27+
@synthesize popover = _popover;
28+
@synthesize viewControllerForPresenting = _viewControllerForPresenting;
29+
@synthesize popOverPresentRect = _popOverPresentRect;
30+
31+
+ (UIImage*)imageWithImage:(UIImage*)sourceImage scaledToSizeWithSameAspectRatio:(CGSize)targetSize;
32+
{
33+
CGSize imageSize = sourceImage.size;
34+
CGFloat width = imageSize.width;
35+
CGFloat height = imageSize.height;
36+
CGFloat targetWidth = targetSize.width;
37+
CGFloat targetHeight = targetSize.height;
38+
CGFloat scaleFactor = 0.0;
39+
CGFloat scaledWidth = targetWidth;
40+
CGFloat scaledHeight = targetHeight;
41+
CGPoint thumbnailPoint = CGPointMake(0.0,0.0);
42+
43+
if (CGSizeEqualToSize(imageSize, targetSize) == NO) {
44+
CGFloat widthFactor = targetWidth / width;
45+
CGFloat heightFactor = targetHeight / height;
46+
47+
if (widthFactor > heightFactor) {
48+
scaleFactor = widthFactor; // scale to fit height
49+
}
50+
else {
51+
scaleFactor = heightFactor; // scale to fit width
52+
}
53+
54+
scaledWidth = width * scaleFactor;
55+
scaledHeight = height * scaleFactor;
56+
57+
// center the image
58+
if (widthFactor > heightFactor) {
59+
thumbnailPoint.y = (targetHeight - scaledHeight) * 0.5;
60+
}
61+
else if (widthFactor < heightFactor) {
62+
thumbnailPoint.x = (targetWidth - scaledWidth) * 0.5;
63+
}
64+
}
65+
66+
CGImageRef imageRef = [sourceImage CGImage];
67+
CGBitmapInfo bitmapInfo = CGImageGetBitmapInfo(imageRef);
68+
CGColorSpaceRef colorSpaceInfo = CGImageGetColorSpace(imageRef);
69+
70+
if (bitmapInfo == kCGImageAlphaNone) {
71+
bitmapInfo = kCGImageAlphaNoneSkipLast;
72+
}
73+
74+
CGContextRef bitmap;
75+
76+
if (sourceImage.imageOrientation == UIImageOrientationUp || sourceImage.imageOrientation == UIImageOrientationDown) {
77+
bitmap = CGBitmapContextCreate(NULL, targetWidth, targetHeight, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);
78+
79+
} else {
80+
bitmap = CGBitmapContextCreate(NULL, targetHeight, targetWidth, CGImageGetBitsPerComponent(imageRef), CGImageGetBytesPerRow(imageRef), colorSpaceInfo, bitmapInfo);
81+
82+
}
83+
84+
// In the right or left cases, we need to switch scaledWidth and scaledHeight,
85+
// and also the thumbnail point
86+
if (sourceImage.imageOrientation == UIImageOrientationLeft) {
87+
thumbnailPoint = CGPointMake(thumbnailPoint.y, thumbnailPoint.x);
88+
CGFloat oldScaledWidth = scaledWidth;
89+
scaledWidth = scaledHeight;
90+
scaledHeight = oldScaledWidth;
91+
92+
CGContextRotateCTM (bitmap, M_PI/2);
93+
CGContextTranslateCTM (bitmap, 0, -targetHeight);
94+
95+
} else if (sourceImage.imageOrientation == UIImageOrientationRight) {
96+
thumbnailPoint = CGPointMake(thumbnailPoint.y, thumbnailPoint.x);
97+
CGFloat oldScaledWidth = scaledWidth;
98+
scaledWidth = scaledHeight;
99+
scaledHeight = oldScaledWidth;
100+
101+
CGContextRotateCTM (bitmap, -M_PI/2);
102+
CGContextTranslateCTM (bitmap, -targetWidth, 0);
103+
104+
} else if (sourceImage.imageOrientation == UIImageOrientationUp) {
105+
// NOTHING
106+
} else if (sourceImage.imageOrientation == UIImageOrientationDown) {
107+
CGContextTranslateCTM (bitmap, targetWidth, targetHeight);
108+
CGContextRotateCTM (bitmap, M_PI);
109+
}
110+
111+
CGContextDrawImage(bitmap, CGRectMake(thumbnailPoint.x, thumbnailPoint.y, scaledWidth, scaledHeight), imageRef);
112+
CGImageRef ref = CGBitmapContextCreateImage(bitmap);
113+
UIImage* newImage = [UIImage imageWithCGImage:ref];
114+
115+
CGContextRelease(bitmap);
116+
CGImageRelease(ref);
117+
118+
return newImage;
119+
}
120+
121+
- (UIImagePickerController *)imagePicker
122+
{
123+
if (!_imagePicker) {
124+
_imagePicker = [[UIImagePickerController alloc] init];
125+
_imagePicker.delegate = self;
126+
}
127+
return _imagePicker;
128+
}
129+
130+
- (UIPopoverController *)popover
131+
{
132+
if (!_popover) _popover = [[UIPopoverController alloc] initWithContentViewController:self.imagePicker];
133+
return _popover;
134+
}
135+
136+
- (void)takePhotoOrChooseFromLibrary
137+
{
138+
self.sources = [[NSMutableArray alloc] init];
139+
self.buttonTitles = [[NSMutableArray alloc] init];
140+
141+
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
142+
[self.sources addObject:[NSNumber numberWithInteger:UIImagePickerControllerSourceTypeCamera]];
143+
144+
[self.buttonTitles addObject:NSLocalizedStringFromTable(@"takePhoto", @"FDTake", @"Option to take photo using camera")];
145+
}
146+
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
147+
[self.sources addObject:[NSNumber numberWithInteger:UIImagePickerControllerSourceTypePhotoLibrary]];
148+
[self.buttonTitles addObject:NSLocalizedStringFromTable(@"chooseFromLibrary", @"FDTake", @"Option to select photo from library")];
149+
}
150+
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
151+
[self.sources addObject:[NSNumber numberWithInteger:UIImagePickerControllerSourceTypeSavedPhotosAlbum]];
152+
[self.buttonTitles addObject:NSLocalizedStringFromTable(@"chooseFromPhotoRoll", @"FDTake", @"Option to select photo from photo roll")];
153+
}
154+
155+
if ([self.sources count]) {
156+
self.actionSheet = [[UIActionSheet alloc] initWithTitle:nil
157+
delegate:self
158+
cancelButtonTitle:nil
159+
destructiveButtonTitle:nil
160+
otherButtonTitles:nil];
161+
for (NSString *title in self.buttonTitles)
162+
[self.actionSheet addButtonWithTitle:title];
163+
[self.actionSheet addButtonWithTitle:NSLocalizedStringFromTable(@"cancel", @"FDTake", @"Decline to proceed with operation")];
164+
self.actionSheet.cancelButtonIndex = self.sources.count;
165+
166+
// If on iPad use the present rect and pop over style.
167+
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
168+
[self.actionSheet showFromRect:self.popOverPresentRect inView:[self presentingViewController].view animated:YES];
169+
}
170+
else {
171+
// Otherwise use iPhone style action sheet presentation.
172+
[self.actionSheet showInView:[self presentingViewController].view];
173+
}
174+
} else {
175+
176+
NSString *str = NSLocalizedStringFromTable(@"noSources", @"FDTake", @"There are no sources available to select a photo");
177+
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
178+
message:str
179+
delegate:self
180+
cancelButtonTitle:nil
181+
otherButtonTitles:nil];
182+
183+
184+
[alertView show];
185+
}
186+
}
187+
188+
- (void)takeVideoOrChooseFromLibrary
189+
{
190+
#warning TODO
191+
}
192+
193+
- (void)takePhotoOrVideoOrChooseFromLibrary
194+
{
195+
#warning TODO
196+
}
197+
198+
#pragma mark - UIActionSheetDelegate
199+
200+
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
201+
{
202+
if (buttonIndex == self.actionSheet.cancelButtonIndex) {
203+
if ([self.delegate respondsToSelector:@selector(takeController:didCancelAfterAttempting:)])
204+
[self.delegate takeController:self didCancelAfterAttempting:NO];
205+
} else {
206+
self.imagePicker.sourceType = [[self.sources objectAtIndex:buttonIndex] integerValue];
207+
208+
// On iPad use pop-overs.
209+
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
210+
[self.popover presentPopoverFromRect:self.popOverPresentRect
211+
inView:[self presentingViewController].view
212+
permittedArrowDirections:UIPopoverArrowDirectionAny
213+
animated:YES];
214+
}
215+
else {
216+
// On iPhone use full screen presentation.
217+
[[self presentingViewController] presentViewController:self.imagePicker animated:YES completion:nil];
218+
}
219+
}
220+
}
221+
222+
#pragma mark - UIAlertViewDelegate
223+
224+
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
225+
{
226+
if ([self.delegate respondsToSelector:@selector(takeController:didCancelAfterAttempting:)])
227+
[self.delegate takeController:self didCancelAfterAttempting:NO];
228+
}
229+
230+
#pragma mark - UIImagePickerControllerDelegate
231+
232+
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
233+
{
234+
// If there is an edited image, take that one!
235+
if ([info objectForKey:UIImagePickerControllerEditedImage]) {
236+
[self.delegate takeController:self gotPhoto:[info objectForKey:UIImagePickerControllerEditedImage] withInfo:info];
237+
} else {
238+
// Otherwise take the original one.
239+
[self.delegate takeController:self gotPhoto:[info objectForKey:UIImagePickerControllerOriginalImage] withInfo:info];
240+
}
241+
[picker dismissModalViewControllerAnimated:YES];
242+
}
243+
244+
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
245+
{
246+
[picker dismissModalViewControllerAnimated:YES];
247+
if ([self.delegate respondsToSelector:@selector(takeController:didCancelAfterAttempting:)])
248+
[self.delegate takeController:self didCancelAfterAttempting:YES];
249+
}
250+
251+
#pragma mark - Presenting view controller method
252+
253+
- (UIViewController*)presentingViewController
254+
{
255+
// Use optional view controller for presenting the image picker if set
256+
UIViewController *presentingViewController = nil;
257+
if (self.viewControllerForPresenting!=nil) {
258+
presentingViewController = self.viewControllerForPresenting;
259+
}
260+
else {
261+
// Otherwise do this stuff (like in original source code)
262+
presentingViewController = [[[UIApplication sharedApplication] keyWindow] rootViewController];
263+
}
264+
return presentingViewController;
265+
}
266+
267+
268+
@end

0 commit comments

Comments
 (0)