您的位置:首页 > 其它

第十一章 Camera笔记

2016-05-09 18:07 253 查看
A,显示图片

      使用UIImageView来显示一张图片,它的contentMode属性可以用于配置图片显示时的压缩方式;

      可以设置为aspect fit为按比率进行压缩图片;

B,添加摄像头的工具栏

       使用UIToolbar来添加工具栏,它的用于类似于UINavigationBar,可以添加多个UIBarButtonItem;

一,使用UIImagePickerController调用camera; 封装了访问底层硬件设备?

        1,可以设置imagePicker的数据源,为camera还是相册等;

        

二,设置UIImagePickerController的代理

         因为UIImagePickerController继承于UINavigationController,所以它的delegate属性来自UINavigationController;

         因此UIImagePickerController的代理需要实现<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,创建BNRImageStore用于保存图片;

        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};

       

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;

     2,NSDictionary 有2大功能:使用key快速遍历数据   以及 易扩展的数据,通过添加key-value改变数据内容;

六,快速找到方法

       #pragma mark  标记方法

七,可以使用imagePicker获取流媒体模式,获取之前同样要去判断是否支持摄像;

八,UIControl

        继承于UIView,当页面需要处理touch事件时,可以使用这个类;

        创建action-target回调;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: