【问题标题】:UITableView within UIScrollView surpassing boundsUIScrollView 中的 UITableView 越界
【发布时间】:2014-06-02 05:36:10
【问题描述】:

在过去的几天里,我为此感到越来越头疼。我正在尝试将一些 UITableViews 添加到滚动视图中,并通过相应的表进行翻页(例如 twitter 的应用程序)。我为屏幕框架使用宏,以便兼容 3.5 和 4 英寸屏幕:

#define screen_x 0
#define screen_y 0
#define screen_width [[UIScreen mainScreen] bounds].size.width
#define screen_height self.view.bounds.size.height
#define screen_frame CGRectMake(screen_x, screen_y, screen_width, screen_height)

我像这样创建了一个 UIScrollView 的实例:

scroll_view = [[UIScrollView alloc] initWithFrame:screen_frame];
scroll_view.backgroundColor = [UIColor clearColor];
scroll_view.contentSize = CGSizeMake(screen_width * 3, screen_height);
scroll_view.bounds = screen_frame;
scroll_view.maximumZoomScale = 1.0;
scroll_view.minimumZoomScale = 1.0;
scroll_view.delegate = self;
scroll_view.bounces = false;
scroll_view.scrollsToTop = NO;
scroll_view.clipsToBounds = true;
scroll_view.pagingEnabled = true;
[self.view addSubview:scroll_view];

我创建一个实例并像这样初始化一个表:

table = [[example_table_view alloc] init_with_frame:CGRectMake(screen_width, 0, screen_width, screen_height) and_array:[information objectForKey:@"information"]];
table.clipsToBounds = true; //attempt to solve
table.bounds = broadcasts_table.frame; //attempt to solve
table.contentSize = scroll_view.contentSize; //attempt to solve
[scroll_view addSubview:table];

问题是,虽然从宏来看,滚动视图的框架和边界似乎是正确的,但表格坚持存在(垂直)在滚动视图之外,部分被 UINavigationBar 和 UITabBar 隐藏(请注意我可能很重要我在我的应用程序中同时使用这两种方法)。

如果有人看到我做错了什么,我将不胜感激。谢谢!

【问题讨论】:

  • 1) 你应该使用约束而不是框架 2) 我真的不喜欢在滚动视图上添加表格视图。
  • 如果是iOS7,需要将scrollview的frame的y值偏移44px。这样的变化必须适应滚动视图和表格视图的高度

标签: iphone objective-c uitableview uiscrollview setcontentview


【解决方案1】:

我上次查看 twitter 应用程序时使用了类似 uipagevuewcontroller 之类的东西在视图之间滑动。

不仅仅是滚动视图。

您可能想先尝试一下。

它在内存使用方面也更加友好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-11
    • 1970-01-01
    相关资源
    最近更新 更多