0

同じビューに 2 つの UIImageView があります。各 imageView には、カメラまたは写真ライブラリから撮影した写真を割り当てる必要があります。それをやり始めると、2つのimageViewで同じ写真が得られます。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    [picker dismissViewControllerAnimated:YES completion:nil];
    imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
    imageView2.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

} 


-(IBAction)addPhoto:(id)sender{

    UIActionSheet *actionSheet =[[UIActionSheet alloc]initWithTitle:@"" delegate:self cancelButtonTitle:@"cancel" destructiveButtonTitle:@"Choose Photo" otherButtonTitles:@"Take Photo ", nil];


    [actionSheet showInView:self.view];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    shouldUpdateFirstImage =YES;
    // chosenImage = info[UIImagePickerControllerEditedImage];
    [picker dismissViewControllerAnimated:YES completion:nil];

  if (shouldUpdateFirstImage) {
        imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
        shouldUpdateFirstImage = NO;
    }
    else {
        pictureView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

        shouldUpdateFirstImage = YES;
    }

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"Put Picture"])
    {
        alrtView.hidden = YES;
        pictureView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,100,100)];
       [self.view addSubview:pictureView];
        [self addPhoto:self];
    }

そしてviewController.h

@interface ViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIActionSheetDelegate,UITextViewDelegate>
{

    BOOL shouldUpdateFirstImage;

}

最初の ImageView は背景です。

4

2 に答える 2