我正在设计一个自己的披萨应用程序。用户可以添加多个配料,例如虾,培根等。所以添加图像工作正常。这是我的代码:
<div class="row comment root" id="1">
<div class="col-md-12">
<div class="row">
<div class="col-xs-1 arrows-block">
<div class="pull-right">
<img src="/images/icon_up_arrow.png" name="up" class="img-responsive resize">
<img src="/images/icon_down_arrow.png" name="down" class="img-responsive resize">
</div>
</div>
<div class="col-xs-11">
<div class="panel panel-default">
<div class="panel-heading">
user 1
</div>
<div class="panel-body">
text 1
</div>
<div class="panel-footer">
<ul class="list-inline">
<li><a class="reply" href="javascript:void(0)">reply</a></li>
<li><a class="expand" href="javascript:void(0)"> expand</a></li>
<li><a class="delete" href="javascript:void(0)"> delete</a></li>
<li><a class="edit" href="javascript:void(0)"> edit</a></li>
</ul>
</div>
</div>
</div>
</div><!-- row -->
</div><!-- col md 12 -->
<div class="row comment root" id="1">
<div class="col-md-12">
<div class="row">
<div class="col-xs-1 arrows-block">
<div class="pull-right">
<img src="/images/icon_up_arrow.png" name="up" class="img-responsive resize">
<img src="/images/icon_down_arrow.png" name="down" class="img-responsive resize">
</div>
</div>
<div class="col-xs-11">
<div class="panel panel-default">
<div class="panel-heading">
user 2
</div>
<div class="panel-body">
text 2
</div>
<div class="panel-footer">
<ul class="list-inline">
<li><a class="reply" href="javascript:void(0)">reply</a></li>
<li><a class="expand" href="javascript:void(0)"> expand</a></li>
<li><a class="delete" href="javascript:void(0)"> delete</a></li>
<li><a class="edit" href="javascript:void(0)"> edit</a></li>
</ul>
</div>
</div>
</div>
</div><!-- row -->
</div><!-- col md 12 -->
</div><!-- comment row -->
调用上述方法的示例:
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];
}
}
如何在用户选择项目时创建切换方法?该项目将添加到视图中,当再次点击时,它应该从视图中删除。
答案 0 :(得分:1)
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
}
}
}