我在scrollview下有imageview。在有图像的imageview中。当我从滚动视图中单击特定图像时,图像将显示为cameraview的叠加。我使用doubleTap删除叠加图像。当我使用doubleTap时,从superview中删除叠加图像。之后,我显示scrollview并选择另一个图像,图像将不会出现在cameraView(叠加)
中代码:
doubleTap的手势:
UITapGestureRecognizer *doubletap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap:)];
doubletap.numberOfTapsRequired=2;
[myImageView addGestureRecognizer:doubletap];
UITapGestureRecognizer *doubletap1=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(doubleTap1:)];
doubletap1.numberOfTapsRequired=2;
[myImageView1 addGestureRecognizer:doubletap1];
doubleTap的方法:
-(void)doubleTap:(UITapGestureRecognizer*)sender{
NSLog(@"image");
[myImageView removeFromSuperview];
}
-(void)doubleTap1:(UITapGestureRecognizer*)sender{
NSLog(@"image1");
[myImageView1 removeFromSuperview];
}
将imageview添加到scrollview:
-(void)unloadPreviousPage:(int)index
{
for(int i=index*4;i<(index+1)*4;i++)
{
[[myScrollView viewWithTag:i+1] removeFromSuperview];
}
}
-(void)loadNextPage:(int)index
{
int countFlag=0;
for(int i=index*4;i<(index+1)*4;i++)
{
UIButton *imageView=[[UIButton alloc]initWithFrame:CGRectMake((320*index)+countFlag*80+ 2, 5, 75, 75)];
imageView7.tag=i+1;
[imageView7 addTarget:self action:@selector(imageViewClicked:) forControlEvents:UIControlEventTouchUpInside];
//[imageView.layer setBorderColor:[UIColor lightGrayColor].CGColor];
// [imageView.layer setBorderWidth:1.0f];
switch ((i+1)%2) {
case 0:
[imageView setImage:[UIImage imageNamed:@"img.png"] forState:UIControlStateNormal];
break;
case 1:
[imageView setImage:[UIImage imageNamed:@"img1.png"] forState:UIControlStateNormal];
break;
}
[myScrollView addSubview:imageView];
countFlag++;
}
}
-(void)imageViewClicked:(id)sender{
switch ([sender tag]%2) {
case 0:
[myImageView setImage:[UIImage imageNamed:@"img.png"]];
break;
case 1:
[myImageView setImage:[UIImage imageNamed:@"img1.png"]];
break;
}
}