iOS 系统相机长按拍照问题

来源:互联网 发布:各国劳动效率数据 编辑:程序博客网 时间:2024/05/21 11:33

最近在调用系统相机上传图片,发现拍照只能长按才可以,google了许多都没发现有遇到过的.自己排查了好长时间.发现是自己项目中的问题.
这是正常的代码:

项目中重写了一个button 的类别 ,导致拍照时的Button事件出现问题.把button类别去掉或者修改就可以了

pragma mark 使用相机 begain

//相机 begain

-(void)selectHeadimage{

[self takePhotoChoice];

}
- (void)takePhotoChoice {
UIActionSheet *myActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@”取消” destructiveButtonTitle:nil otherButtonTitles: @”拍照”, @”相册选择”,nil];
[myActionSheet showInView:[UIApplication sharedApplication].keyWindow];

}
// 调用相机
- (void)takePhoto {
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.allowsEditing = YES;
picker.delegate = self;
picker.allowsEditing=YES;//允许编辑
picker.sourceType = sourceType;

    [self presentViewController:picker animated:YES completion:^{}];}else{    Log(@"无法打开照相机,请在真机中使用");}

}

// 调用相册
- (void)LocalPhoto {

//选择相册图片 修改状态栏颜色UIImagePickerController *ipc = [[UIImagePickerController alloc] init];ipc.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;//修改状态栏颜色UIView* statusView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];statusView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"顶部背景"]];[ipc.view addSubview:statusView];ipc.delegate = self;ipc.allowsEditing = YES;[self presentViewController:ipc animated:YES completion:^{}];

}

pragma mark - UINavigationControllerDelegate

-(void)navigationController:(UINavigationController )navigationController willShowViewController:(UIViewController )viewController animated:(BOOL)animated {

//调相册时 控制状态栏if ([navigationController isKindOfClass:[UIImagePickerController class]] &&    ((UIImagePickerController *)navigationController).sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {    for (UINavigationItem *item in navigationController.navigationBar.subviews) {        if ([item isKindOfClass:[UIButton class]]&&([item.title isEqualToString:@"取消"]||[item.title isEqualToString:@"Cancel"])){            UIButton *button = (UIButton *)item;            [button setEnabled:YES];            [button setHidden:NO];        }    }}[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];[navigationController.navigationBar setTintColor:[UIColor whiteColor]];

}

pragma mark - UIActionSheetDelegate 选择相机or相册事件

  • (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    switch (buttonIndex) {
    case 0:
    [self takePhoto];
    break;
    case 1:
    [self LocalPhoto];
    break;
    }
    }

pragma mark - UIImagePickerControllerDelegate

  • (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    [picker dismissViewControllerAnimated:YES completion:nil];
    }

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

[picker dismissViewControllerAnimated:YES completion:^{}];

}

pragma mark 相机使用 end

0 0
原创粉丝点击