一,使用UIImagePickerController调用camera
二,设置UIImagePickerController的代理
因为UIImagePickerController继承于UINavigationController,所以它的代理需要实现<UINavigationControllerDelegate, UIImagePickerControllerDelegate>
三,显示
1,image picker是以modally的方式显示,它指这种类型的view会一直管理屏幕直到任务完成
2,使用uiviewController的presentViewController:animated:completion:方法来显示image picker
3,获取camera的图片
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { // Get picked image from info dictionary UIImage *image = info[UIImagePickerControllerOriginalImage]; // Put that image onto the screen in our image view self.imageView.image = image; // Take image picker off the screen - // you must call this dismiss method [self dismissViewControllerAnimated:YES completion:nil]; }
四,保存图片
1,要先保存到disk中,需要的时候再加载到RAM中
2,使用NSMutableDictionary数据结构
#import <Foundation/Foundation.h> @interface BNRImageStore : NSObject + (instancetype)sharedStore; - (void)setImage:(UIImage *)image forKey:(NSString *)key; - (UIImage *)imageForKey:(NSString *)key; - (void)deleteImageForKey:(NSString *)key; @end
五,NSDictionary
1,创建,使用快捷方式
NSDictionary *dictionary = @{@"key": object, @"anotherKey": anotherObject};
2,它会将数据保存到disk中,并在使用的时候加载到内存
NSString *imageKey = self.item.imageKey; // Get the image for its image key from the image store UIImage *imageToDisplay = [[BNRImageStore sharedStore] imageForKey:imageKey]; // Use that image to put on the screen in the imageView self.imageView.image = imageToDisplay;
有从disk中保存数据和读取数据的功能?
补充内容:
六,快速找到方法
#pragma mark 标记方法
七,可以使用imagePicker获取流媒体模式,获取之前同样要去判断是否支持摄像;