gpt4 book ai didi

ios - 如何根据其标签值属性在uiimageview上添加图像。?

转载 作者:行者123 更新时间:2023-11-28 21:28:29 25 4
gpt4 key购买 nike

i am opeen a camera on uiimageview tapped event and want to add camera image according to the images tapped. i have four image in my view. Every imageview will open camera separately. Look at my code

- (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];

}

最佳答案

喜欢

第一步

Assign the same method name for your Gestures

UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
singleTap.numberOfTapsRequired = 1;
_first.tag = 1;
[_first setUserInteractionEnabled:YES];
[_first addGestureRecognizer:singleTap];


UITapGestureRecognizer *singleTap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
singleTap1.numberOfTapsRequired = 1;
[_second setUserInteractionEnabled:YES];
_second.tag = 2;
[_second addGestureRecognizer:singleTap1];

第二步

get the tags and pass the tag to imagepickercontroller

 -(void) tapDetected:(UITapGestureRecognizer *)gestureRecognizer{

//Get the View
UIImageView *tabbedIamage = (UIImageView*)gestureRecognizer.view;
NSLog(@"%d",tabbedIamage.tag);
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
// set the tag
picker.view.tag = tabbedIamage.tag;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;

[self presentViewController:picker animated:YES completion:NULL];
}

第三步

set the final image based on tag

 - (void)imagePickerController:(UIImagePickerController *)picker  didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];

if (picker.view.tag == 1)
{
self.first.image = chosenImage;
}
else
{
self.second.image = chosenImage;
}
[picker dismissViewControllerAnimated:YES completion:NULL];

}

关于ios - 如何根据其标签值属性在uiimageview上添加图像。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37209331/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com