IImagePickerController を使用して、フォト ライブラリから写真を取得しています。iPhone では問題なく動作しますが、iPad では動作しません。UIpopoverController を使用するソリューションが提案されました。以前のバージョンでは UIpopoverController を使用していましたが、動作させることができませんでした。popoverController が存在しないというエラーが発生し続けます。以下は私のコードです。UIPopoverController を使用できるフレームワークはありますか?
- (IBAction)getPhoto4:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeSavedPhotosAlbum])
{
UIImagePickerController *imagePicker =[[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.mediaTypes = @[(NSString *) kUTTypeImage ,(NSString *)kUTTypeMovie];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
}
}
#pragma mark -
#pragma mark UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:nil];
UIImage *image = info[UIImagePickerControllerOriginalImage];
float actualHeight = image.size.height;
float actualWidth = image.size.width;
float imgRatio = actualWidth/actualHeight;
float maxRatio = 320.0/480.0;
if(imgRatio!=maxRatio){
if(imgRatio < maxRatio){
imgRatio = 480.0 / actualHeight;
actualWidth = imgRatio * actualWidth;
actualHeight = 480.0;
}
else{
imgRatio = 320.0 / actualWidth;
actualHeight = imgRatio * actualHeight;
actualWidth = 320.0;
}
}
CGRect rect = CGRectMake(0.0, 0.0, actualWidth, actualHeight);
UIGraphicsBeginImageContext(rect.size);
[image drawInRect:rect];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
// Get the data for the image
NSData* imageData = UIImageJPEGRepresentation(img, 1.0);
// Give a name to the file
IMAGE_COUNTER = IMAGE_COUNTER + 1;
NSString* incrementedImgStr = [NSString stringWithFormat: @"zTempDataFilePleaseDelete%d.jpg", IMAGE_COUNTER];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
// Now we get the full path to the file
NSString* fullPathToFile2 = [documentsDirectory stringByAppendingPathComponent:incrementedImgStr];
if(IMAGE_COUNTER == 4) {
imageView4.image = img;
photoHeight4 = img.size.height;
photoWidth4 = img.size.width;
photoPath4 = fullPathToFile2;
}
// and then we write it out
[imageData writeToFile:fullPathToFile2 atomically:NO];
}
-(void)image:(UIImage *)image
finishedSavingWithError:(NSError *)error
contextInfo:(void *)contextInfo
{
if (error) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Save failed"
message: @"Failed to save image"
delegate: nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker1
{
[self dismissViewControllerAnimated:YES completion:nil];
}