Upload
kei-kusakari
View
19.499
Download
4
Embed Size (px)
DESCRIPTION
「iPhone勉強会 at 京都」2008年12月13日の発表資料です。
Citation preview
2008/12/13 2
はじめに
2008/12/13 3
UIImagePickerController とは
iPhone で、 Camera で写真を撮ったり、 Photo Library から写真を選択するためのクラス。
非常に簡単に利用できる。iPhone SDK が提供してい
る、 Camera を使うための公式な唯一の手段。
2008/12/13 4
実際の
ソースコード
2008/12/13 5
@interface CameraViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
UIImagePickerController* cameraController;
}
@property (nonatomic, assign) UIImagePickerController* cameraController;
@end
2008/12/13 6
#define SOURCETYPE UIImagePickerControllerSourceTypeCamera
(省略)
if(![UIImagePickerController isSourceTypeAvailable:SOURCETYPE]){
return;
}
cameraController = [[[UIImagePickerController alloc] init] retain];
cameraController.sourceType = SOURCETYPE;
cameraController.delegate = self;
cameraController.allowsImageEditing = NO;
[self.view.superview addSubview:cameraController.view];
//[self presentModalViewController:cameraController animated:YES];
2008/12/13 7
UIImagePickerControllerSourceType
2008/12/13 8
UIImagePickerControllerSourceType
UIImagePickerControllerSourceTypeCameraCamera で撮影。
UIImagePickerControllerSourceTypePhotoLibraryPhoto Library から画像選択。
UIImagePickerControllerSourceTypeSavedPhotosAlbumSavedPhotoAlbum から画像選択。
2008/12/13 9
Photo Library Saved Photo Album
2008/12/13 10
Camera
2008/12/13 11
UIImagePickerControllerDelegate
2008/12/13 12
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo; {
[picker release];
// 写真選択時の処理
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker release];
// キャンセル時の処理
}
2008/12/13 13
UIImagePickerController に茶茶を入れる
2008/12/13 14
allowsImageEditing =NO
2008/12/13 15
画像編集しない場合
UINavigationControllerDelegate を実装。 Camera, PhotoLibrary 共に表示をいじれる。
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { // 画面カスタマイズコード}
2008/12/13 16
ToyCamera っぽい
カメラインターフェース
を実現
2008/12/13 17
ここを消したい
2008/12/13 18
for (UIView* view in currentView.subviews) {
NSLog(@"view is a %@", [view description]);
}
ひたすら掘ります
2008/12/13 19
その結果
2008/12/13 20
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
UIView* cameraView = [viewController.view.subviews objectAtIndex:0];
UIView* cropOverlay = [cameraView.subviews objectAtIndex:3];
UIView* imgView = [cropOverlay.subviews objectAtIndex:0];
UIView* lcdLayer = [cropOverlay.subviews objectAtIndex:1];
[imgView setHidden: YES];
[lcdLayer setHidden: YES];
}
2008/12/13 21
allowsImageEditing = YES
2008/12/13 22
こんな感じで
表示したい
2008/12/13 23
いろいろやり方を考えた なんとか allowsImageEditing 画面起動を
ハンドリングしたい。 方法を発見できず。
PhotoLibrary 全体に View を載せて、自前判定。 キャンセルが押されたとき、スクロールされた
場合などの処理が複雑。 PhotoLibrary の Photo 上に同じ大きさ
の透明な View を載せる。 Photo 1 つずつのオブジェクトまで辿りつけな
かった。
2008/12/13 24
最終的に行き着いたやり方
2008/12/13 25
View の時間監視
2008/12/13 26
(省略)
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(checkView) userInfo:nil repeats:YES];
touchView = [[MyTouchView alloc] init];
touchView.frame = CGRectMake(0, 0, 320, 480);
touchView.backgroundColor = [UIColor blueColor];
touchView.opaque = YES;
touchView.alpha = 0.5;
touchView.cameraviewcontroller = self;
[self.view.superview addSubview:touchView];
[self.view.superview sendSubviewToBack:touchView];
}
2008/12/13 27
- (void)checkView {
UIView* temp;
[touchView.superview sendSubviewToBack:touchView];
if ((temp = [self getViewFromArray:self.view.superview.subviews num:2]) != nil) {
if((temp = [self getViewFromArray:temp.subviews num:0]) != nil) {
if((temp = [self getViewFromArray:temp.subviews num:1]) != nil) {
if(([[temp description] length] > 15) && ([[[temp description] substringToIndex:15] isEqualToString:@"<PLCropOverlay:"])) {
[touchView.superview bringSubviewToFront:touchView];
}
}
}
}
}
2008/12/13 28
- (UIView *)getViewFromArray:(NSArray*)viewArray num:(int)i {
if([viewArray count] <= i) return nil;
return [viewArray objectAtIndex:i];
}
2008/12/13 29
最後に
2008/12/13 30
非公開 API を使えばもう少しいろいろできるみたいで
す。
興味がある方はそちらも調べてみて下さい。
2008/12/13 31
ご静聴ありがとうございました!