首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自不同UIImage视图的多张相机胶卷图像-照片拼贴应用

来自不同UIImage视图的多张相机胶卷图像-照片拼贴应用
EN

Stack Overflow用户
提问于 2013-01-11 12:27:48
回答 1查看 1.2K关注 0票数 0

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

ViewController.h

代码语言:javascript
复制
#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

View Controller.m

代码语言:javascript
复制
#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

建议?请HELPPPP!

EN

回答 1

Stack Overflow用户

发布于 2013-11-01 19:28:36

建议:

创建一个可以保存所有imageView对象的NSMutableArray。因此,在获取新图像时..您可以在相应的imageView中设置它们,获取它的框架并替换它

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14271677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档