OS X 有一個(gè)特有的控件叫做 IKPictureTaker,允許用戶從計(jì)算機(jī)上選擇一張圖片,或者從攝像頭捕捉一張圖片。當(dāng)用戶選擇了圖片之后,這個(gè)控件會(huì)調(diào)用指定的代理方法。

系統(tǒng)圖片選取

攝像頭選取

實(shí)現(xiàn)效果圖
1.API
-(void) beginPictureTakerSheetForWindow:(NSWindow *)aWindow withDelegate:(id) delegate didEndSelector:(SEL) didEndSelector contextInfo:(void *) contextInfo;
2.import
#import <Quartz/Quartz.h>
3.實(shí)現(xiàn)代碼
[[IKPictureTaker pictureTaker] beginPictureTakerSheetForWindow:[NSApplication sharedApplication].keyWindow withDelegate:self didEndSelector:@selector(pictureTakerDidEnd:returnCode:contextInfo:) contextInfo:nil];
4.代理方法
- (void)pictureTakerDidEnd:(IKPictureTaker *)picker returnCode:(NSInteger)code contextInfo:(void*)contextInfo{
NSImage * image = [picker outputImage];
if (image) {
self.imageView.image = image;
}
NSLog(@"NSImage:%@",image);
NSLog(@"code:%ld",code);
}