iOS滚动图片

时间:2013-02-25 23:08:31

标签: ios objective-c uiscrollview scroll

在寻找教程之后,看到很多关于滚动图像的答案,我很难在Lane Splitter中选择字符时实现UIScrollView。 在这个卷轴中,我感兴趣的区域是小图像。我想做同样的事。

另一个让我感兴趣的例子应该是来自Itunes的封面流程,但左边和右边没有图像。只是中心的图像和相同的动画。

感谢您的帮助! =)

1 个答案:

答案 0 :(得分:0)

-(id)init{
   self = [super init];
   if (self){
     UIScrollView *scroller = [[UIScrollView alloc] initWithFrame:CGRectMake(30, 155, 265, 180)];
        [scroller setBackgroundColor:[UIColor lightGrayColor]];
        [scroller setPagingEnabled:YES];
        [scroller setDelegate:self];
        [self addSubview:scroller];

     NSArray *arrayOfImages = [NSArray alloc] initWithObjects images, nil];
}

-(void)setScrollView:(UIScrollView *)scroller1 :(NSArray *)array{
    for (int i = 0; i < array.count; i++) {
        CGRect frame;
        frame.origin.x = scroller.frame.size.width * i;
        frame.origin.y = 0;
        frame.size = scroller.frame.size;

        UIImageView *newPageView = [[UIImageView alloc] initWithImage:[array objectAtIndex:i]];
        newPageView.contentMode = UIViewContentModeScaleAspectFit;
        newPageView.frame = frame;
        [scroller addSubview:newPageView];

    }

    scroller.contentSize = CGSizeMake(scroller.frame.size.width * array.count, scroller.frame.size.height);
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setScrollView:scroller :arrayOfImages];
}

我相信这应该有效。它是一个scrollview并插入uiimageviews

相关问题