来自不同 UIImage 视图的相机胶卷的多个图像 - 照片拼贴应用 [英] Multiple Images From Camera Roll In Different UIImage Views - Photo Collage App

查看:21
本文介绍了来自不同 UIImage 视图的相机胶卷的多个图像 - 照片拼贴应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

So this has been annoying the hell out of me. What I want to do is create a photo collage app where there are multiple image views and I will place buttons over the image views and when a user clicks the button it brings up the camera roll and you can choose an image and it places it in that image view. The problem I am having is that everytime a user chooses an image, it only places it in one image view even though I have declared more than one. The image just keeps getting replaced. Below is my code.

视图控制器.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

视图控制器.m

#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

建议???请帮助PPP!!!

Suggetions??? PLEASE HELPPPP!!!

推荐答案

建议:

制作一个 NSMutableArray,您可以在其中保存所有 imageView 对象.所以在获取新图像时..你可以在各自的图像视图中设置它们,获取它的框架并替换它

make an NSMutableArray where you can keep all the imageView objects. so while getting the new image.. you can set them in the respective imageView, get its frame and replace it

这篇关于来自不同 UIImage 视图的相机胶卷的多个图像 - 照片拼贴应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆