我是靠谱客的博主 隐形百合,最近开发中收集的这篇文章主要介绍ios自定义拍照界面和选取图片界面总结,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

//自定义拍照界面
- (void)photograph {
    
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = self;   // 设置委托
        imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        imagePickerController.allowsEditing = YES;
        imagePickerController.showsCameraControls = NO;
        
        
        UIButton *selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [selectButton setImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
        
        [selectButton setTranslatesAutoresizingMaskIntoConstraints:NO];
        
        [selectButton addTarget:self action:@selector(selectButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
        
        [imagePickerController.view addSubview:selectButton];
        
        UIButton *cancleCameraBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [cancleCameraBtn setTitle:@"取消拍摄" forState:UIControlStateNormal];
        [cancleCameraBtn setTranslatesAutoresizingMaskIntoConstraints:NO];
        [cancleCameraBtn addTarget:self action:@selector(cancleCameraBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
        [imagePickerController.view addSubview:cancleCameraBtn];
        
        NSLayoutConstraint *constraintBottom = [NSLayoutConstraint constraintWithItem:selectButton attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:imagePickerController.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
        
        NSLayoutConstraint *contraintCenterX = [NSLayoutConstraint constraintWithItem:selectButton attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:imagePickerController.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0];
        
        NSLayoutConstraint *constraintRightX = [NSLayoutConstraint constraintWithItem:cancleCameraBtn attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:imagePickerController.view attribute:NSLayoutAttributeRight multiplier:1 constant:0];
        
        NSLayoutConstraint *constraintBottomCancle = [NSLayoutConstraint constraintWithItem:cancleCameraBtn attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:imagePickerController.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0];
        
        [imagePickerController.view addConstraints:[NSArray arrayWithObjects:constraintBottom ,contraintCenterX ,constraintRightX,constraintBottomCancle,nil]];
        
        [self presentViewController:imagePickerController animated:YES completion:nil];  //需要以模态的形式展示
    }
}

- (void)selectButtonPressed:(UIButton *)sender {
    
    [imagePickerController takePicture];
}


//自定义选取图片界面

- (void)photoLibrary{
    //初始化UIImagePickerController 指定代理
    imagePickerController = [[UIImagePickerController alloc] init];
    //选择类型相机,相册还是什么
    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    //指定代理 因此我们要实现 UIImagePickerControllerDelegate,UINavigationControllerDelegate 协议
    imagePickerController.delegate = self;
    //不允许编辑
    imagePickerController.allowsEditing = NO;
    //显示相册
    [self presentViewController:imagePickerController animated:YES completion:nil];
}
//选取照片结束调用
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
    [picker dismissViewControllerAnimated:YES completion:^{}];
    imagePickerController = nil;
    [self performSelector:@selector(changeImageSize:) withObject:image];
}
//需要自定义选取图片界面
<pre name="code" class="objc">//不允许编辑
    imagePickerController.allowsEditing = NO;
//需要自定义拍照界面
 
<pre name="code" class="objc">imagePickerController.showsCameraControls = NO;



 


 
 


最后

以上就是隐形百合为你收集整理的ios自定义拍照界面和选取图片界面总结的全部内容,希望文章能够帮你解决ios自定义拍照界面和选取图片界面总结所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(46)

评论列表共有 0 条评论

立即
投稿
返回
顶部