gpt4 book ai didi

ios - 在同一个 UIImageView 中删除和添加多个图像

转载 作者:行者123 更新时间:2023-11-29 01:11:38 27 4
gpt4 key购买 nike

我正在设计一个自己制作的披萨应用程序。用户可以添加多种配料,例如虾、培根等。所以添加图像工作正常。这是我的代码:

bool meatAdded;
- (void)addMeatTopping:(NSString*)meat withImage:(UIImageView*)meatImage {
if ((meatAdded =! meatAdded)) {
//crust o taqir bede be cheese BADAN
meatImage = [[UIImageView alloc]initWithFrame:_crustImage.bounds];
[meatImage setImage:[UIImage imageNamed:meat]];
[_crustImage addSubview:meatImage];

for (UIButton*button in _meatButtonsArray) {
checkMark.center = button.center;
checkMark.alpha = 1;
}

[UIView animateWithDuration:.60 delay:0 usingSpringWithDamping:.40 initialSpringVelocity:.20 options:UIViewAnimationOptionAllowUserInteraction animations:^ {
meatImage.transform = CGAffineTransformMakeScale(.5, .5);
meatImage.transform = CGAffineTransformMakeScale(1, 1); } completion:nil];
}else {
/**** THIS PART OF CODE DOESN'T WORK ! IT PRINTS LOG BUT DOESN'T CHANGE THE MEAT IMAGE AT ALL ****/

NSLog(@"Remove");
meatImage.alpha = 0;
[meatImage setImage:nil];
[meatImage removeFromSuperview];
}
}

调用上述方法的示例:

- (IBAction)meat0:(id)sender {
[self addMeatTopping:@"topping_Bacon" withImage:beykenMeat];
}

- (IBAction)meat1:(id)sender {
[self addMeatTopping:@"Steak" withImage:steykMeat];
}

当用户选择一个项目时,如何创建切换方法?该项目将添加到 View 中,再次点击时它应该从 View 中删除。

最佳答案

SubclassImageView *imageviewG = [[SubclassImageView alloc]initWithFrame:CGRectMake(0, 0, 200, 200)];
self.crustImage = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 250, 250)];
self.crustImage.backgroundColor = [UIColor redColor];
[imageviewG setImage:@"topping_Bacon"];

[self.crustImage addSubview:imageviewG];
[self.view addSubview:self.crustImage];

for(id viewInner in self.crustImage.subviews){
if([viewInner isKindOfClass:[SubclassImageView class]]){
SubclassImageView *imageSeleted = (SubclassImageView *)viewInner;
if([imageSeleted.getImageName isEqualToString:@"topping_Bacon"]){
//your logic to add or remove the imageview from super view
}else if([imageSeleted.getImageName isEqualToString:@"Steak"]){
//your logic to add or remove the imageview from super view
}
}
}

关于ios - 在同一个 UIImageView 中删除和添加多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35684691/

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