滚动视图功能不完全



目前,我正在开发一个使用滚动视图的移动应用程序。在该滚动视图中有页面。我需要显示 8 页。但是现在,移动应用程序中仅显示5个页面。我不知道错误发生在哪里。请问谁能帮我?

下面是我的代码。

  self.MainScrollview.delegate = self;
    [self.view addSubview:self.MainScrollview];
    CGSize scrollViewContentSize = CGSizeMake(self.MainScrollview.frame.size.width*5, 380);
    [self.MainScrollview setContentSize:scrollViewContentSize];
    [self.MainScrollview setPagingEnabled:YES];
    self.MainScrollview.showsHorizontalScrollIndicator = NO;
    self.MainScrollview.backgroundColor = [UIColor clearColor];
    //[self.view addSubview:self.MainScrollview];
    self.pageControl = [[UIPageControl alloc] init];
    self.pageControl.frame = CGRectMake(0,440,320,20);
    if (iOSDeviceScreenSize.height == 568){
        self.pageControl.frame = CGRectMake(0,440+50,320,20);
    }else{
        if (versionCheck >= 7)
            self.pageControl.frame = CGRectMake(0,440+20,320,20);
    }
    self.pageControl.numberOfPages = 8;
    self.pageControl.currentPage = self.productNum;
    self.pageControl.backgroundColor = [UIColor clearColor];
    self.pageControl.enabled = NO;
    //self.pageControl.pageIndicatorTintColor = [UIColor colorWithRed:0/255.0 green:73/255.0 blue:144/255.0 alpha:1.0];
    [self.view addSubview:self.pageControl];
    // Product 1
    UIScrollView* scrollview = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
    scrollview.contentSize = CGSizeMake(290, 380);
    scrollview.backgroundColor = [UIColor clearColor];
    scrollview.zoomScale = 1.0;
    [self.MainScrollview addSubview:scrollview];
    UIImage *i1 = [UIImage imageNamed:@"roundedbox3.png"];
    UIImageView *iv1 = [[UIImageView alloc] initWithImage:i1];
    iv1.frame = CGRectMake(10, 10, 601/2, 755/2);
    [scrollview addSubview:iv1];
    UIImage *producUp = [UIImage imageNamed:@"Enfamama-A+.png"];
    UIImageView *producUpV = [[UIImageView alloc] initWithImage:producUp];
    producUpV.contentMode = UIViewContentModeScaleAspectFit;
    producUpV.frame = CGRectMake(10 , 0, 600/2, 978/2);
    [scrollview addSubview:[self addImageToScrollView:producUpV]];

    UIButton *moreInfoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [moreInfoBtn setBackgroundImage:[UIImage imageNamed:@"moreInfoProd.png"] forState:UIControlStateNormal];
    moreInfoBtn.frame = CGRectMake(15+70, 343, 264/2, 87/2);
    [moreInfoBtn addTarget:self action:@selector(getMoreInfo) forControlEvents:UIControlEventTouchUpInside];
    [scrollview addSubview:moreInfoBtn];
    UIButton *sampleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [sampleBtn setBackgroundImage:[UIImage imageNamed:@"freesampleProd.png"] forState:UIControlStateNormal];
    sampleBtn.frame = CGRectMake(320-25-129, 345, 258/2, 87/2);
    [sampleBtn addTarget:self action:@selector(getSample) forControlEvents:UIControlEventTouchUpInside];
    //[scrollview addSubview:sampleBtn];

如果你期待 8 页,那么你的代码的第三行不应该从这里改变吗?

CGSize scrollViewContentSize = CGSizeMake(self.MainScrollview.frame.size.width*5, 380);

对此

CGSize scrollViewContentSize = CGSizeMake(self.MainScrollview.frame.size.width*8, 380);

这意味着您需要将宽度从 5 倍增加到 8

最新更新