repeat an image when scrolling on iphone

…衆ロ難τιáo~ 提交于 2019-12-07 15:27:48

问题


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:

is this possible? it should feel like an infinite loop


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/3770591/repeat-an-image-when-scrolling-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!