repeat an image when scrolling on iphone

2019-05-10 10:17发布

i've got an UIImageView, now i want to repeat this image, that it always shows up again when scrolling left or right.

Little Example:

alt text

is this possible? it should feel like an infinite loop

2条回答
Summer. ? 凉城
2楼-- · 2019-05-10 10:57

If you don't care about performance, you can use a "pattern image":

UIView * backgroundView = [[[UIView alloc] initWithFrame:frame] autorelease];
backgroundView.backgroundColor = [UIColor colorWithPatternImage:repeatingImage];

I think it just draws it to the view's context, though, which means it can't be "infinite" and performance might be a bit slow.

查看更多
手持菜刀,她持情操
3楼-- · 2019-05-10 11:17

The word "infinite" rules out a UISCrollView or a CATiledLayer, obviously.

I'd say the easiest way to achieve this is to initialize enough UIImageViews to completely fill your screen (or scroll area), plus one, and implement your own dragging/scrolling system and recycle the UIImageViews as they go off one side of the screen to reappear on the other side. Because all the UIImageViews are the same image you shouldn't ever have to worry about memory/cache management.

查看更多
登录 后发表回答