gpt4 book ai didi

iphone - dismissViewControllerAnimated 不适用于 iPhone 5

转载 作者:行者123 更新时间:2023-11-28 20:17:13 28 4
gpt4 key购买 nike

所以在我的 iPhone 4 设备中,当我选择一张图片后,我希望图片选择器弹出窗口消失。这适用于 iPhone 4,但以下代码不适用于 iPhone 5。

- (void) loadImage:(UIImage*) image {
float w = image.size.width;
float h = image.size.height;
float maxw = scrollView.frame.size.width;
float maxh = scrollView.frame.size.height;
float wratio = maxw / w;
float hratio = maxh / h;
float ratio = wratio < hratio ? wratio : hratio;
ratio = ratio < 1 ? ratio : 1;

int adjW = (int) (w * ratio);
int adjH = (int) (h * ratio);

UIGraphicsBeginImageContext(CGSizeMake(adjW, adjH));
CGContextRef context = UIGraphicsGetCurrentContext();
[image drawInRect:CGRectMake(0, 0, adjW, adjH)];

CGImageRef scaledImage = CGBitmapContextCreateImage(context);

UIGraphicsEndImageContext();

[appDelegate.model setCurrentImage:[UIImage imageWithCGImage: scaledImage]];
[self clear];
calcButton.enabled = YES;
trashButton.enabled = YES;
scribbleControls.enabled = YES;
[appDelegate.mergeViewCtlr setFirst];
}

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self loadImage:[info objectForKey:UIImagePickerControllerOriginalImage]];

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
if ([popoverController isPopoverVisible]) {
// called for iPad
[popoverController dismissPopoverAnimated:YES];
}
}
else {
// called for iPhone and tried each of the next 3 lines individually
[self dismissModalViewControllerAnimated:YES]; <== NOT WORKING
[self dismissViewControllerAnimated:YES completion:nil]; <== ALSO NOT WORKING
[picker dismissViewControllerAnimated:YES completion:nil]; <== ALSO NOT WORKING
}

[picker release];
}

我还注意到它说 dimissModelViewControllerAnimated 已被弃用,我应该使用:使用 dismissViewControllerAnimated:completion: 代替。但我将如何使用它?谢谢

这是呈现模型 View 的代码: - (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {

switch (buttonIndex) {
case 0: { //photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}
else {
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
popoverController.delegate = self;
[popoverController presentPopoverFromRect:CGRectMake( 250, -50, 320, 480 )
inView:[self view]
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
}
else { // for iPhone
[self presentModalViewController:imagePicker animated:TRUE];
}
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Photo library is empty or unavailable" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
break;
}
case 1: //camera

最佳答案

dismissModalViewControllerAnimated::deprecated in iOS6 .请改用 dismissViewControllerAnimated:completion:

关于iphone - dismissViewControllerAnimated 不适用于 iPhone 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17601273/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com