为什么这个基于UIScrollView的轮播没有响应水平滑动?

时间:2013-09-24 20:05:05

标签: iphone ios ipad uiscrollview carousel

我有点简化:

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0,
    200 /*self.view.frame.size.width*/,
    (self.view.frame.size.height - 20) / 3)];

UIImage *cardImage = [UIImage imageNamed:@"note1"];
CGSize cardSize = [cardImage size];
CJSHCardView *cardView = [[CJSHCardView alloc] initWithImage:cardImage];
[cardView rotate];
[cardView setContentMode:UIViewContentModeScaleAspectFit];
[cardView setFrame:CGRectMake(0, 20, cardSize.width * scale, cardSize.height * scale)];
[cardView setDescription:@"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?"];
[cardView setOnWeb:[NSURL URLWithString:@"https://www.google.com"]];
[scrollView addSubview:cardView];

for(int i = 0; i < 10; ++i)
{
    UIImage *noteImage2 = [UIImage imageNamed:@"note2"];
    CGSize noteSize2 = [noteImage2 size];
    UIImageView *imageView2 = [[UIImageView alloc] initWithImage:noteImage2];
    CGRect bounds2 = imageView2.bounds;
    CJSHCardView *noteView2 = [[CJSHCardView alloc] initWithImage:noteImage2];
    [noteView2 rotate];
    [noteView2 setContentMode:UIViewContentModeScaleAspectFit];
    [noteView2 setFrame:CGRectMake(100 + 100 * i, 20, noteSize2.width * scale, noteSize2.height * scale)];
    [scrollView addSubview:noteView2];
}
[containerView addSubview:scrollView];

在200像素宽或注释宽度时,它会显示一定数量的图像,最右边的图像会被切除。但是,UIScrollView不滚动。我尝试过左右手(单个)手指滑动,图像没有移动像素。

这里有什么问题?我是否需要进行其他配置才能获得类似轮播的滚动?有没有更好的课程来实现滚动在一个维度上的轮播?

谢谢,

1 个答案:

答案 0 :(得分:0)

为了在iOS上实现轮播,我发现这个项目在实现方面非常灵活且易于使用:

https://github.com/nicklockwood/iCarousel

有很好的例子可以让你加快使用速度。

希望这有帮助!