我打開uiimageview點擊事件的相機,並希望根據點擊的圖像添加相機圖像。在我看來,我有四個形象。每個imageview將單獨打開相機。看看我的代碼如何根據標籤值屬性在uiimageview上添加圖像。
- (void)viewDidLoad {
[super viewDidLoad];
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Device has no camera"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[myAlertView show];
}
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];
singleTap.numberOfTapsRequired = 1;
[_first setUserInteractionEnabled:YES];
[_first addGestureRecognizer:singleTap];
_first.tag = 1;
UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetectedforsecondimage)];
singleTap1.numberOfTapsRequired = 1;
[_second setUserInteractionEnabled:YES];
[_second addGestureRecognizer:singleTap1];
_second.tag = 2;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(void)tapDetected{
NSLog(@"single Tap on imageview");
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
-(void)tapDetectedforsecondimage
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
self.second.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:NULL];
}
什麼是第一個和第二個... –
這些是圖像名稱先生,我有我的視圖中的四個圖像 –