UIImagePickerController有3个按钮

时间:2014-11-11 16:49:45

标签: objective-c ios7 uiimagepickercontroller

我有3个按钮可以激活相机。一旦选择了使用照片,每个应该将图像选择器的图像作为背景。但是,我无法让它正常工作。我可以得到第一个和最后一个使用图像,或者所有可以拍摄图像,但只有第一个背景发生变化。我现在包括我所拥有的东西,谢谢你的帮助。

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSString *mediaType = info[UIImagePickerControllerMediaType];

    [self dismissViewControllerAnimated:YES completion:nil];

    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
        UIImage *image = info[UIImagePickerControllerOriginalImage];

        _imageView.image = image;
        if (_newMedia)
            UIImageWriteToSavedPhotosAlbum(image,
                                           self,
                                           @selector(image:finishedSavingWithError:contextInfo:),
                                           nil);
        self.camera1.tag = 1;
        self.camera2.tag = 1;
        self.camera3.tag = 1;

        if ([self.camera1 isEqual:self.camera1]) {          
            [self.camera1 setBackgroundImage:image forState:UIControlStateNormal];
            [self.camera1 setTitle:@"" forState:UIControlStateNormal];
            [self.camera1 setImage:nil forState:UIControlStateNormal];
            self.camera1.tag++;


        } else if ([self.camera2 isEqual:self.camera2]) {
            [self.camera2 setBackgroundImage:image forState:UIControlStateNormal];
            [self.camera2 setTitle:@"" forState:UIControlStateNormal];
            [self.camera2 setImage:nil forState:UIControlStateNormal];

        } else if([self.camera3 isEqual:self.camera3]) {
            [self.self.camera3 setBackgroundImage:image forState:UIControlStateNormal];
            [self.self.camera3 setTitle:@"" forState:UIControlStateNormal];
            [self.self.camera3 setImage:nil forState:UIControlStateNormal];

        }
    }
    else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
    {
        // not using video...don't need anything here
    }
}

-(void)useCamera:(id)sender {

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    [self presentViewController:picker animated:YES completion:nil];
}

1 个答案:

答案 0 :(得分:1)

哦好的,只是这样做:

[self.activeButton setImage:[info objectForKey:UIImagePickerControllerOriginalImage]] 
里面的 didFinishPacking 方法。在此之前,您应该添加一个UIButton * activeButton变量,每次用户点击按钮时都会设置该变量(例如,它可以是IBAction)。

另外,如果您使用IBOutlets,请确保连接了UIButton的插座。