OS X 有一個特有的控件叫做 IKPictureTaker,允許用戶從計(jì)算機(jī)上選擇一張圖片吱肌,或者從攝像頭捕捉一張圖片驹马。當(dāng)用戶選擇了圖片之后,這個控件會調(diào)用指定的代理方法笆制。
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);
}