-1

嗨,我有一个包含图像数组的 UiScroll 视图,我可以来回滑动以推进加载的图像。但是,我也希望能够通过按钮操作来控制滚动视图的前进。这是滚动视图的代码:

int PageCount = 28;

        NSMutableArray *arrImageName =[[NSMutableArray alloc]initWithObjects:@"S2-4.png",@"D3-4.png",@"F2-4.png",@"B6-4.png",@"D6-4.png",@"S1-4.png",@"B7-4.png", @"D2-4.png",@"F7-4.png",@"B1-4.png",@"F3-4.png",@"D5-4.png",@"S3-4.png",@"B2-4.png",@"F5-4.png",@"D4-4.png",@"S7-4.png",@"F1-4.png",@"B3-4.png",@"S4-4.png",@"F6-4.png",@"D1-4.png",@"B4-4.png",@"S5-4.png",@"F4-4.png",@"D7-4.png",@"S6-4.png",@"B5-4.png",nil];

        scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
        scroller.scrollEnabled=YES;
        scroller.backgroundColor = [UIColor clearColor];
        [scroller setShowsHorizontalScrollIndicator:NO];
        scroller.pagingEnabled = YES;
        scroller.bounces = NO;
        [self.view addSubview:scroller];
        width=scroller.frame.size.width;
        xPos=0;
        for (int i=0; i<PageCount; i++)
        {
            UIImageView *ImgView = [[UIImageView alloc]initWithFrame:CGRectMake(xPos, 0, scroller.frame.size.width, scroller.frame.size.height)];
            [ImgView setImage:[UIImage imageNamed:[arrImageName objectAtIndex:i]]];
            [scroller addSubview:ImgView];
            scroller.contentSize = CGSizeMake(width, 0);
            width +=scroller.frame.size.width;
            xPos  +=scroller.frame.size.width;
        }

然后我有我的按钮动作,但我将如何使用按钮执行相同的推进?谢谢你。

- (void)nextPhoto: (id)sender {

}

我对 xcode 比较陌生,不确定如何在此操作中操作滚动视图。

4

1 回答 1

1

看看 scrollRectToVisible:animated: - 它将很好地滚动到特定位置。

于 2013-08-21T15:35:36.467 回答