0

我有一个空白屏幕,我在其中单击相机按钮并拍照,然后该照片在我的空白屏幕上显示为 a UIVIew,并且我正在将多个图像从相机添加到空白屏幕。问题是有时我可以在空白屏幕上添加多个图像,但有时当我捕获图像时,空白屏幕上的所有图像都会消失,只显示当前图像。

在此处输入图像描述

- (IBAction)openCameraOnAddButton:(id)sender {
//NSLog(@"openCameraOnAddButton");
[AddImagesToCanvasView setHidden:YES];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];  
picker.delegate = self; 
picker.sourceType = UIImagePickerControllerSourceTypeCamera;  
[self presentModalViewController:picker animated:YES];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[picker dismissModalViewControllerAnimated:YES];
UIImage *image = [[info objectForKey:@"UIImagePickerControllerOriginalImage"] retain];


UIView *holderView;
if(image.size.width > image.size.height || image.size.width == image.size.height)
{
    holderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 180, 160)];
}
else{
    holderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 160, 240)];
}
UIImageView *imageview = [[UIImageView alloc] initWithFrame:[holderView frame]];
[imageview setImage:image];
NSLog(@"Tag By Default %d",(arc4random()%100)+10);
[holderView setTag:(int)objectDelegate.tagForHolderView];
[imageview setTag:((int)objectDelegate.tagForHolderView)+1];
[holderView addSubview:imageview];


UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scale:)];
[pinchRecognizer setDelegate:self];
[holderView addGestureRecognizer:pinchRecognizer];

 UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotate:)];
 [rotationRecognizer setDelegate:self];
 [holderView addGestureRecognizer:rotationRecognizer];

UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(move:)];
[panRecognizer setMinimumNumberOfTouches:1];
[panRecognizer setMaximumNumberOfTouches:1];
[panRecognizer setDelegate:self];
[holderView addGestureRecognizer:panRecognizer];

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapped:)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setDelegate:self];
[holderView addGestureRecognizer:tapRecognizer]; 


 UILongPressGestureRecognizer *gestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(gestureHandler:)];
 [holderView addGestureRecognizer:gestureRecognizer];

[holderView.layer setBorderColor: [[UIColor whiteColor] CGColor]];
[holderView.layer setBorderWidth: 3.0];
[self.view addSubview:holderView];
objectDelegate.tagForHolderView+=2;

}
4

1 回答 1

0

不确定,但是当您执行所有操作时,UIImagePickerCotroller 的委托方法有时可能无法正常工作。

我在将图像存储在文档目录中时遇到了同样的问题,为了解决这个问题,我在didFinishPickingMediaWithInfo方法中创建了新线程并在该方法中移动了整个代码。然后它对我来说很好。尝试这样做。

于 2012-11-27T15:58:16.920 回答