ios - 在第一张图片之外的其他地方启动 ScrollView

标签 ios objective-c uiscrollview

您好,我想看看我是否可以使用我在下面创建的 ScrollView 并在第 3 或第 4 个图像上启动 ScrollView ,而不是从头开始 ScrollView 。基本上我不希望它从第一张图片开始,但仍然能够向后滚动以找到它们。这可能吗?谢谢你!

int PageCount = 34;
        NSMutableArray *arrImageName =[[NSMutableArray alloc]initWithObjects:@"4miley.png",@"4BP1-2.png",@"S2-4.png",@"D3-4.png",@"4BP1-1.png",@"F2-4.png",@"B6-4.png",@"D6-4.png",@"4BP1-3.png",@"S1-4.png",@"B7-4.png", @"D2-4.png",@"F7-4.png",@"B1-4.png",@"F3-4.png",@"4BP1-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",@"4BP1-5.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, 480)];
        scroller.scrollEnabled=YES;
        scroller.backgroundColor = [UIColor clearColor];
        [scroller setShowsHorizontalScrollIndicator:NO];
        scroller.pagingEnabled = YES;
        scroller.bounces = NO;
        scroller.delegate = self;
        [self.view addSubview:scroller];
        width=scroller.frame.size.width;
        xPos=0;
        for (int i=0; i<PageCount; i++)
        {
            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;
        }

最佳答案

在scrollview中初始化图片后,可以使用scrollRectToVisible方法来显示第3张和第4张图片,在该方法中设置第3张图片的边框。

[scroller scrollRectToVisible:frame animated:YES];
//frame = your 3rd image 

关于ios - 在第一张图片之外的其他地方启动 ScrollView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19441412/

相关文章:

objective-c - swift 中的 Objective C static const

ios - 作为 subview 添加到 Collection View 单元格时, ScrollView 中的内容不可见

ios - 如何快速缩放多个页面中的图像

ios - 打印出 firebase 子值

ios - "Error occurred"ios 应用程序中的 facebook 登录

ios - UIDocumentInteractionController可以预览哪些文件类型?

ios - 如何从iOS中为for循环创建的所有文本字段中获取文本

iOS View Controller 包含 | subview Controller 将触摸传递给父 View Controller

ios - Unity 中的粘性 UITableView 滚动

iphone - UITableViewCell 内的水平 UIScrollView