gpt4 book ai didi

ios - Xcode - 如何关闭模态 UIImageView?

转载 作者:行者123 更新时间:2023-11-29 12:39:35 24 4
gpt4 key购买 nike

iOS 开发的新手。我正在尝试做一个让我从照片库中选择照片并显示它的东西。我正在使用带有导航 Controller 的 Storyboard。我可以很好地选择和显示图像,但我不知道如何关闭 imageview 并返回到图像选择器。我只是得到一个全屏图像,无法点击任何地方做任何事情。代码如下所示:

snapViewController.h 

#import <UIKit/UIKit.h>

@interface snapViewController : UIViewController <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>

@property (strong, nonatomic) IBOutlet UIImageView *ImageView;

- (IBAction) done:(UIStoryboardSegue *)unwindsegue;

@end

我的.m

snapViewController.m 


#import "snapViewController.h"

@interface snapViewController ()

@end

@implementation snapViewController


- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (BOOL)prefersStatusBarHidden {
return YES;
[self setNeedsStatusBarAppearanceUpdate];
}


- (void) viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
if (self.ImageView.image == nil){
UIImagePickerController * imagePickerController = [UIImagePickerController new];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.delegate = self;
[self presentViewController:imagePickerController animated:NO completion:nil];
}
else {

}



}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:nil];

}

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
self.ImageView.image = image;
[self.ImageView setUserInteractionEnabled:YES];
[self dismissViewControllerAnimated:YES completion:nil];


}

- (IBAction) done:(UIStoryboardSegue *)unwindsegue {


}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}



@end

Storyboard看起来像这样,我在 UIImageView 的底部贴了一个工具栏,上面有一个完成按钮: storyboard我是否需要将完成按钮绑定(bind)到 [self dismissViewControllerAnimated:YES completion:nil]; 操作?我怎样才能做到这一点?我已经为此苦苦挣扎了几个小时,但无法弄清楚。谢谢。

最佳答案

阅读了一些关于 View 和窗口以及 View Controller 和其他东西的内容,得出了这个:

- (IBAction)kill:(id)sender {
self.ImageView.image = nil;
[self viewDidAppear:TRUE];
[self dismissViewControllerAnimated:NO completion:nil];

}

我将我的完成按钮绑定(bind)到它,看起来它可以工作。这似乎是可以接受的内存明智的(多次打开和关闭图像不会使内存增加到原来的数量)。如果这不是正确的方法,请告诉我。谢谢。

关于ios - Xcode - 如何关闭模态 UIImageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25346646/

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