繁体   English   中英

iPad的照片选择器和相机

[英]Photo Picker and Camera for iPad

我有编码从照片库或相机附加文件,这是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];

popover中的用户图像选择器。

UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM