Skip to content

Instantly share code, notes, and snippets.

@cqa02303
Created December 21, 2009 06:49
Show Gist options
  • Save cqa02303/260822 to your computer and use it in GitHub Desktop.
Save cqa02303/260822 to your computer and use it in GitHub Desktop.
#pragma mark -
#pragma mark ButtonAction // ボタンの応答
// 写真ソース選択を出す
- (IBAction)pictAction:(id)sender {
NSLog(@"pictAction");
[((TakePhotoView*)self.view) finderCloseForceAction:self];
UIActionSheet *sheet = [UIActionSheet alloc];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
if (self.appDelegate.sourceImage == nil) {
sheet = [[sheet initWithTitle:@"Select a Photo Source" delegate:self cancelButtonTitle:@"CANCEL" destructiveButtonTitle:nil otherButtonTitles:@"Built in Camera", @"Photo Albums", @"Camera Roll", nil] autorelease];
}else {
sheet = [[sheet initWithTitle:@"Select a Photo Source" delegate:self cancelButtonTitle:@"CANCEL" destructiveButtonTitle:nil otherButtonTitles:@"Built in Camera", @"Photo Albums", @"Camera Roll", @"History", nil] autorelease];
}
}else {
if (self.appDelegate.sourceImage == nil) {
sheet = [[sheet initWithTitle:@"Select a Image Source" delegate:self cancelButtonTitle:@"CANCEL" destructiveButtonTitle:nil otherButtonTitles:@"Photo Albums", @"Saved Photos", nil] autorelease];
}else {
sheet = [[sheet initWithTitle:@"Select a Image Source" delegate:self cancelButtonTitle:@"CANCEL" destructiveButtonTitle:nil otherButtonTitles:@"Photo Albums", @"Saved Photos", @"History", nil] autorelease];
}
}
[sheet showFromTabBar:self.tabBar];
}
#pragma mark -
#pragma mark UIActionSheetDelegate // アクションシートの応答
// ソースセレクト
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(@"button hit:%d / %d", buttonIndex, actionSheet.numberOfButtons);
AudioServicesPlaySystemSound(self.appDelegate.bu);
int num = actionSheet.numberOfButtons;
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
buttonIndex --;
num--;
}
if (buttonIndex >= 2) {
if (buttonIndex + 1 != num) {
// History表示
NSLog(@"History view");
appDelegate.icon57ViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:self.appDelegate.icon57ViewController animated:YES];
}else {
// cancelボタン
}
return;
}
[[NSNotificationCenter defaultCenter] postNotificationName:kStartActivityNotification object:nil];
[self performSelector:@selector(showImagePicker:) withObject:[NSNumber numberWithInt:buttonIndex] afterDelay:0.1f];
}
// イメージピッカーの遅延実行
- (void) showImagePicker:(NSNumber*)number {
NSLog(@"showImagePicker");
int buttonIndex = [number intValue];
// イメージピッカー作成
UIImagePickerController *controller = [[[UIImagePickerController alloc] init] autorelease];
// controller.mediaTypes = [NSArray arrayWithObjects:(id)kUTTypeImage, nil];
switch (buttonIndex) {
case -1:
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
controller.cameraOverlayView = self.cameraOverlay;
[self performSelector:@selector(removeOverlayView:) withObject:controller afterDelay:0.1f];
break;
case 0:
controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
break;
case 1:
default:
controller.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
break;
}
// 応答はAppDelegateで行う
controller.allowsEditing = YES;
controller.delegate = self.appDelegate;
controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:controller animated:YES];
}
// overlay viewを外すけどlayerツリーは残す
- (void) removeOverlayView:(UIImagePickerController*)controller {
CALayer *splayer = self.cameraOverlay.layer.superlayer;
controller.cameraOverlayView = nil;
[splayer addSublayer:self.cameraOverlay.layer];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment