Xcode 多张来自不同UIImage视图中的摄影机滚动图像-照片拼贴应用程序

Xcode 多张来自不同UIImage视图中的摄影机滚动图像-照片拼贴应用程序,xcode,uiimageview,Xcode,Uiimageview,所以这让我非常恼火。我想做的是创建一个照片拼贴应用程序,其中有多个图像视图,我将在图像视图上放置按钮,当用户单击按钮时,它会调出相机卷,您可以选择一个图像并将其放置在该图像视图中。我遇到的问题是,每次用户选择一个图像时,它只将其放在一个图像视图中,即使我声明了多个图像视图。图像不断被替换。下面是我的代码 ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController <

所以这让我非常恼火。我想做的是创建一个照片拼贴应用程序,其中有多个图像视图,我将在图像视图上放置按钮,当用户单击按钮时,它会调出相机卷,您可以选择一个图像并将其放置在该图像视图中。我遇到的问题是,每次用户选择一个图像时,它只将其放在一个图像视图中,即使我声明了多个图像视图。图像不断被替换。下面是我的代码

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
    UIImagePickerController *imagePicker;
    UIImagePickerController *imagePickerTwo;
}

@property (retain, nonatomic) IBOutlet UISwitch *toggleCamera;
@property (retain, nonatomic) IBOutlet UIImageView *imageViewOne;
@property (retain, nonatomic) IBOutlet UIImageView *imageViewTwo;
- (IBAction)buttonOne:(id)sender;
- (IBAction)buttonTwo:(id)sender;

@end
建议???请帮忙

建议:

制作一个NSMutableArray,您可以在其中保存所有imageView对象。 因此,在获得新形象的同时。。您可以在相应的imageView中设置它们,获取其框架并替换它

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize toggleCamera;
@synthesize imageViewOne;
@synthesize imageViewTwo;


- (void)viewDidLoad
{   imagePicker = [[UIImagePickerController alloc] init];
    imagePickerTwo = [[UIImagePickerController alloc] init];

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [self setImageViewOne:nil];
    [self setImageViewTwo:nil];
    [self setToggleCamera:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (void)dealloc {
    [imageViewOne release];
    [imageViewTwo release];
    [toggleCamera release];
    [super dealloc];
}


- (IBAction)buttonOne:(id)sender {

    UIImagePickerController *imagePicker;
    imagePicker = [[UIImagePickerController alloc] init];

    if ([self.toggleCamera isOn]) {
        imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
    }else {
        imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    }
    imagePicker.delegate=self;

    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [self presentModalViewController:imagePicker animated:YES];

    }

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    [self dismissModalViewControllerAnimated:YES];
    self.imageViewOne.image=[info objectForKey:
                                    UIImagePickerControllerOriginalImage];
} 


- (IBAction)buttonTwo:(id)sender {
    UIImagePickerController *imagePickerTwo;
    imagePicker = [[UIImagePickerController alloc] init];

    if ([self.toggleCamera isOn]) {
        imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
    }else {
        imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    }
    imagePicker.delegate=self;

    [[UIApplication sharedApplication] setStatusBarHidden:YES];
    [self presentModalViewController:imagePicker animated:YES];

}

-(void)imagePickerController2:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [[UIApplication sharedApplication] setStatusBarHidden:NO];
    [self dismissModalViewControllerAnimated:YES];
    self.imageViewTwo.image=[info objectForKey:
                             UIImagePickerControllerOriginalImage];
}
@end