开发者

Implementing scroll view that is much larger than the screen view with random images

开发者 https://www.devze.com 2022-12-28 18:55 出处:网络
What I\'m trying to do is to implement something like the fruit machine scroll view. Basically I have a sequence of images (randomly generated on the fly) and I want to allow the users to scroll throu

What I'm trying to do is to implement something like the fruit machine scroll view. Basically I have a sequence of images (randomly generated on the fly) and I want to allow the users to scroll through this line. There can fit approx 10 images on the screen, but the line is virtually unlimited.

My question is what would be the best approach in implementing this?

So far I've thought of having a UIImageView going across the screen (with width equal to the sum of 10 images) and the image associated with it would be a combination of 12 or so images, with two images falling out of the visible area, this would allow for smooth scrolling. If the user scrolls further, then I would reconstruct the image associated with the view so the new images are appended and the old one's are discarded.

This image reconstruction business sounds bit complicated, so I was wondering if there's a more logical way to implement this.

There's one more thing, I want to have two lines crossing each other with images, bit l开发者_如何转开发ike conveyor belts crossing. If that makes any sense... Bit like below:

      V1
      V2
H1 H2 H3 H4 H5
      V4
      V5

So if the vertical belt is moved it'd be like:

      V2
      H3
H1 H2 V4 H4 H5
      V5
      V6

H1-H5, V1-V6 being automatically generated images.

I'm not asking for the implementation code, just the thoughts on the principles how to implement this. Thanks!! :)


I would just keep them all as separate UIImageViews and animate them in concert (using UIView animations). That way you let CoreAnimation take care of rendering into layers. Once an image goes offscreen you can destroy it - and create new ones ready to come onscreen at the other end. A more sophisticated approach would involve a pool of offscreen UIImageViews so you don't immediately destroy (and may never destroy). That would be somewhat like the way a UITableView is implemented - only you'd be rolling your own (if it was just vertical columns I'd suggest UITableViews).

If I get what you're trying to do I think the performance should be fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号