如何在模板图像中的特定区域添加图像
这是一个模板图像( http://sofzh.miximages.com/ios/9ME6A.jpg ),其中有多个圆形区域可用。 我们需要,当我们点击任何圆形区域(逐个)时,画廊应该是打开的,并且在从图库中选择图像后,应该在所选圆形区域上显示图像。 请提供我的问题的任何链接或演示。 我在这里。
谢谢!
- 使用5个“UIImageView”视图创建一个viewController。 根据需要安排
- 放置你的微笑图像。
- 将UITapGestureRecognizer添加到每个UIImageView中并捕获它们
- 打开UIImagePicker并将您的VC作为委托
- 捕获用户选择的图片事件并将图像放置到具体的UIImageView
您应该从后端获取模板图像中圆形图像的映射(位置和尺寸),并使用这些值显示圆形并从图库中选择图像。
如果您获得包含所有圆圈的单个图像,则在单个图像中识别所有圆圈(使用复杂算法)将非常困难。
如果后端能够提供映射数据,则第一种方法是正确的方法。
在ViewController.h中
#import #import @interface ViewController : UIViewController @property (strong, nonatomic) IBOutlet UIImageView *imageView1; @property (strong, nonatomic) IBOutlet UIImageView *imageView2; @property (strong, nonatomic) IBOutlet UIImageView *imageView3; @property (strong, nonatomic) IBOutlet UIImageView *imageView4; @property (strong, nonatomic) IBOutlet UIImageView *imageView5; @end
ViewController.m
#import "ViewController.h" @interface ViewController () { UIImageView *imageviewPick; } @end @implementation ViewController @synthesize imageView1,imageView2,imageView3,imageView4,imageView5; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. imageView1.layer.cornerRadius = self.imageView1.frame.size.height / 2; imageView1.layer.borderWidth = 1.0f; imageView1.layer.borderColor = [[UIColor grayColor] CGColor]; imageView1.layer.masksToBounds = YES; imageView2.layer.cornerRadius = self.imageView2.frame.size.height / 2; imageView2.layer.borderWidth = 1.0f; imageView2.layer.borderColor = [[UIColor grayColor] CGColor]; imageView2.layer.masksToBounds = YES; imageView3.layer.cornerRadius = self.imageView3.frame.size.height / 2; imageView3.layer.borderWidth = 1.0f; imageView3.layer.borderColor = [[UIColor grayColor] CGColor]; imageView3.layer.masksToBounds = YES; imageView4.layer.cornerRadius = self.imageView4.frame.size.height / 2; imageView4.layer.borderWidth = 1.0f; imageView4.layer.borderColor = [[UIColor grayColor] CGColor]; imageView4.layer.masksToBounds = YES; imageView5.layer.cornerRadius = self.imageView5.frame.size.height / 2; imageView5.layer.borderWidth = 1.0f; imageView5.layer.borderColor = [[UIColor grayColor] CGColor]; imageView5.layer.masksToBounds = YES; UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImageOne:)]; tap1.numberOfTapsRequired = 1; UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImageTwo:)]; tap2.numberOfTapsRequired = 1; UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImageThree:)]; tap3.numberOfTapsRequired = 1; UITapGestureRecognizer *tap4 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImageFour:)]; tap4.numberOfTapsRequired = 1; UITapGestureRecognizer *tap5 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapImageFive:)]; tap4.numberOfTapsRequired = 1; imageView1.userInteractionEnabled = YES; imageView2.userInteractionEnabled = YES; imageView3.userInteractionEnabled = YES; imageView4.userInteractionEnabled = YES; imageView5.userInteractionEnabled = YES; [imageView1 addGestureRecognizer:tap1]; [imageView2 addGestureRecognizer:tap2]; [imageView3 addGestureRecognizer:tap3]; [imageView4 addGestureRecognizer:tap4]; [imageView5 addGestureRecognizer:tap5]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } -(void)tapImageOne:(UIGestureRecognizer *)tapGesture { imageviewPick = (UIImageView *)tapGesture.view; [self showGallery]; } -(void)tapImageTwo:(UIGestureRecognizer *)tapGesture { imageviewPick = (UIImageView *)tapGesture.view; [self showGallery]; } -(void)tapImageThree:(UIGestureRecognizer *)tapGesture { imageviewPick = (UIImageView *)tapGesture.view; [self showGallery]; } -(void)tapImageFour:(UIGestureRecognizer *)tapGesture { imageviewPick = (UIImageView *)tapGesture.view; [self showGallery]; } -(void)tapImageFive:(UIGestureRecognizer *)tapGesture { imageviewPick = (UIImageView *)tapGesture.view; [self showGallery]; } -(void)showGallery { UIImagePickerController *pickImage = [[UIImagePickerController alloc]init]; pickImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; pickImage.delegate = self; [self presentViewController:pickImage animated:YES completion:nil]; } -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; imageviewPick.image = image; [picker dismissViewControllerAnimated:YES completion:nil]; } @end