【问题标题】:How to achieve 2 dimensional scrolling on iPhone如何在 iPhone 上实现二维滚动
【发布时间】:2010-09-08 04:19:27
【问题描述】:

我正在尝试在我的应用程序中创建类似 excel 的视图。为此,我想同时实现水平 n 垂直滑动。即,如果垂直滚动将填充行,而水平滚动将填充列.. 不知道如何开始。

【问题讨论】:

    标签: iphone objective-c uiscrollview


    【解决方案1】:

    这是一个有趣的问题。我肯定会说从 UIScrollView 开始,并将内容大小设置为大于屏幕大小,具体大小取决于您。

    接下来,您需要进行某种实现,以有效地确定屏幕上的单元格。如果我是你,我会做与 UITableView 类似的事情,即创建一个自定义对象,根据滚动视图的偏移量跟踪屏幕上的索引。

    接下来,您将需要这个自定义对象直接或间接地让可见单元格在它们可见时在屏幕上显示它们自己,并在它们不可见时将它们从超级视图中删除。我还建议重用屏幕外的视图。

    这是您正在尝试制作的具有中等挑战性的东西,因此请确保您很有条理,不要害怕制作一些新的自定义对象来执行特定任务。

    示例接口文件:

     @protocol doubleTableViewDelegate
    
     -(NSInteger)heightForRow:(NSInteger)row;
     -(NSInteger)widthForCol:(NSInteger)col;
    
     -(NSInteger)numberOfRows:(NSInteger)rows;
     -(NSInteger)numberOfCols:(NSInteger)cols;
    
     -(UIView *)cellForRow:(NSInteger)row col:(NSInteger)col;     //get the custom table view to store and dequeue these, i.e. store them in an NSSet when they go offscreen, and give them back when a certain function is called.
    
     //There's probably a few functions missing here still.
    
     @end
    
     @interface doubleTableView: UIScrollView {
          id<doubleTableViewDelegate> infoDelegate;
     }
    
     //your functions to show and remove cells as needed
    
     @end
    

    您需要解决其余的问题,但请继续更新此页面,我会尽力提供帮助。 祝你好运,告诉我进展如何。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-09
      • 2020-03-04
      • 1970-01-01
      相关资源
      最近更新 更多