zoukankan      html  css  js  c++  java
  • 访问相册, 从相册中选取图片

    @interface OneViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate>{

        UIImageView *imageView;

    }

    @end

    @implementation OneViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.view.backgroundColor = [UIColor yellowColor];

        

        

        //UIImageView 继承于UIView

        imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 150)];

        imageView.backgroundColor = [UIColor grayColor];

        [self.view addSubview:imageView];

        

        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];

        button.frame = CGRectMake(100, 200, 100, 100);

        button.layer.cornerRadius = 50;

        [button addTarget:self action:@selector(camera) forControlEvents:(UIControlEventTouchUpInside)];

        [button setTitle:@"相机" forState:(UIControlStateNormal)];

        [self.view addSubview:button];

        button.backgroundColor = [UIColor redColor];

        

        UIButton *mButton = [UIButton buttonWithType:(UIButtonTypeCustom)];

        mButton.frame = CGRectMake(50, 400, 100, 50);

        [mButton addTarget:self action:@selector(photo) forControlEvents:(UIControlEventTouchUpInside)];

        mButton.backgroundColor = [UIColor redColor];

        [mButton setTitle:@"相册" forState:(UIControlStateNormal)];

        [self.view addSubview:mButton];

    }

    - (void)camera {

        //判断是否由摄像头

        BOOL isCamera = [UIImagePickerController isCameraDeviceAvailable:(UIImagePickerControllerCameraDeviceRear)];

    //UIImagePickerControllerCameraDeviceRear后置摄像头

     //前置摄像头UIImagePickerControllerCameraDeviceFront

        if (!isCamera) {

            NSLog(@"没有后置摄像头");

            return;

        }

        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        imagePicker.delegate = self;

        imagePicker.editing = YES;//相机照的照片是否允许编辑

        [self presentViewController:imagePicker animated:YES completion:^{

        }];

        

    }

    //调取相册

    - (void)photo {

        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];

        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentViewController:imagePicker animated:YES completion:^{

            NSLog(@"打开系统相册");

        }];

        imagePicker.delegate = self;

        [imagePicker release];

    }

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {

        //选取相册照片

        imageView.image = image;

        [self dismissViewControllerAnimated:YES completion:^{

        }];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    go-elasticsearch 来自官方的 golang es client
    nginx unit nodejs 模块试用(续)
    WebSocket-Over-HTTP Protocol
    pushpin Server-sent events && openresty 集成试用
    Rendering on the Web
    pushpin openresty 集成试用
    100 webhook implementations
    streamdataio 实时数据分发平台
    Generic Realtime Intermediary Protocol
    Pushpin How it works
  • 原文地址:https://www.cnblogs.com/hsxblog/p/4948361.html
Copyright © 2011-2022 走看看