在 MonoTouch 中处理在多个屏幕之间来回滑动的架构方法 [英] Architectural approach to handling swiping back and forth between many screens in MonoTouch

查看:27
本文介绍了在 MonoTouch 中处理在多个屏幕之间来回滑动的架构方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 MonoTouch 为 iOS 开发一个应用程序.

I am developing an app in MonoTouch for iOS.

该功能的很大一部分是用户需要在数据的页面(屏幕)之间连续滑动并来回滑动.

A big part of the functionality is that the user will need to swipe between pages (screens) of data continuously and go back and forth.

我需要记住内存消耗,所以我的想法是我一次只能有几个屏幕.例如,只提前延迟加载下一个屏幕,所以当用户滑动到它时它是可用的.(或滑动时延迟加载).

I need to keep in mind memory consumption, so my thought is I could only have a few screens in memory at a time. For example, lazy load the next 1 screen ahead of time only, so it's available when the user swipes to it. (Or lazy load on swipe).

当用户滑回到他们所在的上一页时,我需要确保该页面仍在内存中并且没有离开内存.一些落后的页面,一旦用户向后滑动,我可以懒惰地重新加载.因此,如果用户有一段时间没有查看屏幕,我将需要一种机制将屏幕发送到 GC,并在用户滑动到该页面时自动加载它们.

When the user swipes back to a previous page they were on, I need to make sure that that page is still in memory and hasn't left memory. Pages that are a few behind, I can lazy re-load once the user swipes back. Therefore, I will need a mechanism to send screens to GC if they have not been viewed by the user in a while and have them automatically loaded when the user swipes to that page.

我正在考虑创建一个对象列表,其中每个对象都有关于在视图上显示什么的信息以及对实际视图本身的引用.如果此引用为空,则我知道要创建视图.如果引用存在且未处理,我可以只向用户显示现有引用.当用户左右滑动时,我可以转到列表中的下一个(或上一个)项目并执行相同的操作.检查它是否有视图引用并加载该视图,或创建它.

I was thinking of creating a List of objects where each object has information about what to display on the view along with a reference to the actual view itself. If this reference is null, I know to create the view. If the reference exists and is not disposed I can just show the user that existing reference. As the user swipes left and right, I can go to the next (or prev) item in the list and do the same thing. Check if it has a view reference and load that view, or create it.

性能是这里的关键,因为用户可能会在数百个(或更多)屏幕上滑动.

Performance is key here, as the user may be swiping through potentially hundreds (or more) of screens.

对速度和内存管理的最佳架构有什么想法吗?

Any thoughts on the best architecture for speed and memory management?

推荐答案

关键是尽可能重用视图.在我的应用程序中,我向左/向右滑动类似于我认为你想要的,我只需要创建最多三个视图:一个用于屏幕上",然后向右/向左离开屏幕(尽管在需要时才创建左)).

Key would be to reuse views if possible. In my app I have swiping left/right similar to what I think you want, and I just have to create up to three views: one for "on screen" and then right/left off-screen (although left is not created until needed).

通过在线程中尽可能多地构建与页面相关的内容,并在主线程上更新 UI,您可以获得相当多的创意.此外,在移动到右侧不可见页面之前,在加载新数据集时,我肯定会首先关注将要可见的页面,如果有意义,则左侧不可见页面.当用户滑动到新页面时,视图会被重用并在更大的 UIScrollView 内容区域周围移动.

You can get pretty creative by doing as much as possible related to your page build-out in a thread and just update the UI on main thread. Also I definitely focus first on the to-be visible page when loading new dataset before moving to the right not visible page and, if it makes sense, left not visible page. When user swipes to new page, the views get reused and moved around the larger UIScrollView content area.

这篇关于在 MonoTouch 中处理在多个屏幕之间来回滑动的架构方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆