ios - 适用于 iPad 的照片选择器和相机

标签 ios image ipad photo

我有代码可以从照片库或最适合 iPhone 的相机附加文件。但是对于 iPAD,我开始知道必须使用 popUpViewController。谁能推荐在 iPad 中附加图片的代码?

我的代码是

-(void)openCamera
{
@try
{
      UIImagePickerController *picker = [[UIImagePickerController alloc] init];
      picker.delegate = self;
      picker.sourceType = UIImagePickerControllerSourceTypeCamera;
      picker.navigationBar.tintColor = [UIColor blackColor];
      [self.navigationController presentViewController:picker animated:YES completion:nil];



}
@catch (NSException *exception)
{
    CustomAlertView *alert = [[CustomAlertView alloc] initWithTitle:@"No Camera"
                                                            message:@"Camera is not available  "
                                                           delegate:self cancelButtonTitle:@"Ok"
                                                  otherButtonTitles:nil];
    [alert show];

}
}

-(void)pick
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.navigationBar.tintColor = [UIColor blackColor];
[self presentViewController:picker animated:YES completion:nil];

}

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

if (picker.sourceType == UIImagePickerControllerSourceTypeCamera)
{

    [picker dismissViewControllerAnimated:YES completion:nil];

    UIImage *fullImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];

    UIImage *thumbImage = [fullImage imageByScalingAndCroppingForSize:CGSizeMake(180,180)];
    self.detailItem.fullImage = fullImage;
    self.detailItem.thumbImage = thumbImage;

    NSData *dataObj = UIImagePNGRepresentation(thumbImage);
    base64String=[dataObj base64Encoding];

    NSDate *currentDateTime = [NSDate date];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"MMddyyyy_HHmmss"];
    NSString *dateInStringFormated = [dateFormatter stringFromDate:currentDateTime];

    fileName = [NSString stringWithFormat:@"IMG_%@.png",dateInStringFormated];

    [self Uploadfile];
}
else
{
    [picker dismissViewControllerAnimated:YES completion:nil];

    UIImage *fullImage = (UIImage *) [info objectForKey:UIImagePickerControllerOriginalImage];


    UIImage *thumbImage = [fullImage imageByScalingAndCroppingForSize:CGSizeMake(180,180)];
    self.detailItem.fullImage = fullImage;
    self.detailItem.thumbImage = thumbImage;

    NSData *dataObj = UIImagePNGRepresentation(thumbImage);
    base64String=[dataObj base64Encoding];

    NSURL *imageURL = [info valueForKey:UIImagePickerControllerReferenceURL];
    ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
    {
        ALAssetRepresentation *representation = [myasset defaultRepresentation];
        fileName = [representation filename];
        NSLog(@"fileName siva : %@",fileName);
        [self Uploadfile];

    };

    ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
    [assetslibrary assetForURL:imageURL
                   resultBlock:resultblock
                  failureBlock:nil];       



}


}

最佳答案

试试这个

UIImagePickerController *imagePickerController= [[UIImagePickerController alloc]init];
[imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePickerController setDelegate:self];
self.popoverPickerController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
[self.popoverPickerController presentPopoverFromRect:CGRectMake(0,0,100,100) inView:[self teilnehmerCollectionView] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

关于ios - 适用于 iPad 的照片选择器和相机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17830771/

相关文章:

ios - UITableView 附件 CheckMark 在单元格内移动标签

ios - 缩小时注释消失

ios - 由于内存原因,App在iPad 1和iPad 2上崩溃的原因更多:为什么?

javascript - 不变违规 : requireNativeComponent: "BVLinearGradient"

ios - AVPlayer 向后搜索时不更新 currentPlaybackTime

python - 如何使用 pygtk 前进到 "new page"?

html - 如何将图像编码为 HTML 文件

android - 怎样消除图片周围的黑边

javascript - 检测iPhone/iPad并更改CSS文件

iphone - 将 Target 从 iPhone- 更新到 Universal-App