iOS 访问相机、相册

#pragma mark - 访问相册\相机

-(void)puzzlesButton

{

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

    imagePickerController.delegate = self;

    imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;//访问相册

    //UIImagePickerControllerSourceTypeCamera//访问相机

    [self presentViewController:imagePickerController animated:YES completion:nil];

    

}


#pragma mark - 获取相片-退出相册

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

{

    ((UIView*)[picker.view.subviews objectAtIndex:0]).frame = CGRectMake(0, 0, 320, 480-130);

    

    if ([picker sourceType] == UIImagePickerControllerSourceTypePhotoLibrary)

    {

        NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

        if ([mediaType isEqualToString:@"public.image"])

        {

            UIImage *imageJPEG = [info objectForKey:UIImagePickerControllerOriginalImage];//选取器控制器的原始图像

            

            

            

            self.loginView.image = imageJPEG;

            [self dismissViewControllerAnimated:YES completion:nil];

            

        }else{

            UIAlertView *alert = [[UIAlertView alloc]

                                  initWithTitle:@"图片添加已满"

                                  message:@""

                                  delegate:nil

                                  cancelButtonTitle:@"OK!"

                                  otherButtonTitles:nil];

            [alert show];

           

        }

    }

}




转载请注明出处:http://blog.csdn.net/sevenquan


你可能感兴趣的:(ios,ios,ios,访问相机,访问相机相册,访问相册)