0

我有按钮来显示滚动视图。我在 awesomeView 下有三张图片。然后我将 awesomeView 添加到 scrollView 以进行滚动。当我单击任何图像时,awesomeView 将被添加到 myImageView8。因为 myImageView8 将 awesomeview 图像显示到屏幕中心。当 myImageView8 或 awesomeView 在屏幕上可见时,我需要隐藏它

代码:

scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 420, self.view.frame.size.width, self.view.frame.size.height)];
scroll.pagingEnabled = YES;
NSInteger numberOfViews = 3;
for (int i = 0; i < numberOfViews; i++) {
    //  CGFloat xOrigin = i * self.view.frame.size.width;
    // awesomeView = [[UIView alloc] initWithFrame:CGRectMake(xOrigin, 0, self.view.frame.size.width, self.view.frame.size.height)];

    awesomeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height)];

    awesomeView.backgroundColor=[UIColor clearColor];
    [scroll addSubview:awesomeView];

    img = [UIButton buttonWithType:UIButtonTypeCustom];

    [img setImage:[UIImage imageNamed:@"img.png"] forState:UIControlStateNormal];
    // [overlayButton setFrame:CGRectMake(80, 420, 60, 30)];

    [img setFrame:CGRectMake(0, 0, 100,130)];

    [img addTarget:self action:@selector(img:) forControlEvents:UIControlEventTouchUpInside];
    [img setTag:0];

    [awesomeView addSubview:img];

    img1 = [UIButton buttonWithType:UIButtonTypeCustom];
    [img1 setImage:[UIImage imageNamed:@"sofa_s2.png"] forState:UIControlStateNormal];
    // [overlayButton setFrame:CGRectMake(80, 420, 60, 30)];
    [img1 setFrame:CGRectMake(110, 0, 100,130)];
    [img1 setTag:1];

    [img1 addTarget:self action:@selector(img1:) forControlEvents:UIControlEventTouchUpInside];
    [awesomeView addSubview:img1];

    img2 = [UIButton buttonWithType:UIButtonTypeCustom];
    [img2 setImage:[UIImage imageNamed:@"sofa_s3.png"] forState:UIControlStateNormal];
    // [overlayButton setFrame:CGRectMake(80, 420, 60, 30)];

    [img2 setFrame:CGRectMake(210, 0, 100,130)];
    [img2 setTag:2];
    [img2 addTarget:self action:@selector(img2:) forControlEvents:UIControlEventTouchUpInside];
    [awesomeView addSubview:img2];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width * numberOfViews, self.view.frame.size.height);
[self.view addSubview:scroll];

myImageView8 用于在屏幕中心显示真棒:

myImageView8=[[UIImageView alloc]initWithFrame:CGRectMake(0, 50, 320, self.view.frame.size.height)];
[self.view addSubview:myImageView8];
myImageView8.userInteractionEnabled=YES;

-(void)img:(id)sender {
    if(myImageView8){
        [myImageView8 removeFromsuperView];
    } 
    else {
        [myImageView8 addSubView:awesomeView];
    }
}

-(void)img1:(id)sender {
    if(myImageView8) {
        [myImageView8 removeFromsuperView];
    }
    else {
        [myImageView8 addSubView:awesomeView];
    }
}

-(void)img2:(id)sender {
    if(myImageView8) {
        [myImageView8 removeFromsuperView];
    }
    else {
    [myImageView8 addSubView:awesomeView];
    }
}

如果我单击按钮,则会显示滚动。但是当我单击图像时,如果 myImageView8 可见,它会重新出现。

在此处输入图像描述

4

0 回答 0