简体   繁体   中英

Capturing Image in Iphone

I have a blank screen on which i click camera button and take photo and than that photo appears on my blank screen as a UIVIew and i'm adding multiple images from Camera to blank screen. The problem is sometimes i can add multiple images on blank screen but sometimes when i capture image and than all images on blank screen disappear and just shows the current image.

在此处输入图片说明

- (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;

}

Not sure but as you are doing all the operation UIImagePickerCotroller's delegate methods sometimes it may not work.

I faced same problem while storing the image in document directory & to resolve this i had created new Thread in didFinishPickingMediaWithInfo method & moved entire code in that method. Then after it works fine for me. Try to do that.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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