Ios UIScrollView不考虑动态子视图位置 编辑:1/12/2013
。已更新的源以反映。 我很想结束这个问题,并给一个适当的“dup”链接,但我也没有这方面的声誉。我是一个多么悲伤的小男人 免责声明:这是一个潜在的过于复杂的观点,我的工作可能是误导的意图。我非常愿意接受这样一种可能性:我遗漏了一些关键的信息/诀窍,试图做一些iOS根本做不到的事情,或者我做得完全错误。如果是这样的话,我会很高兴地接受一个让我信服的答案,或者只是在我的头上扔一个文件/沉重的书,上面有一个页码,我可以用RTFM 一般问题 对于大型应用程序中的一个视图,我试图向用户展示一个包含四个主要元素的垂直滚动屏幕。从上到下列出,如下所示:;关于一件事的一些一般信息,一个UITextView,一个相关内容的列表,一个UITableView,因为每个都代表实际应用程序中的一个潜在序列,示例中的一些更多信息,一个UILabel和一个可操作按钮一个UIButton。TableView中相关内容的单元格数量根据所呈现内容的不同而不同。因此,我找到了一种方法来调整tableView的大小,并相应地移动UILabel和UIButton,详细内容如下,在ViewDidDisplay中完成:。它工作得很好,很漂亮,可以滚动,让我很高兴,但当我按下按钮时,它会跳回到它在Interface Builder视图中所处的位置,完全不考虑对其框架所做的编程更改 问题 为什么?? 它可以被修复吗?如果可以,如何修复? 是否有不同和/或更好的方法 我想发布一些照片来展示到底发生了什么,但我没有这个名声,所以我有一个演示项目的完整来源,见上文。你可以随意乱搞代码,直接看看发生了什么 所有细节 请跳过这些 我在Interface Builder和代码中组合的屏幕组织如下:Ios UIScrollView不考虑动态子视图位置 编辑:1/12/2013,ios,interface-builder,xcode4.5,Ios,Interface Builder,Xcode4.5,。已更新的源以反映。 我很想结束这个问题,并给一个适当的“dup”链接,但我也没有这方面的声誉。我是一个多么悲伤的小男人 免责声明:这是一个潜在的过于复杂的观点,我的工作可能是误导的意图。我非常愿意接受这样一种可能性:我遗漏了一些关键的信息/诀窍,试图做一些iOS根本做不到的事情,或者我做得完全错误。如果是这样的话,我会很高兴地接受一个让我信服的答案,或者只是在我的头上扔一个文件/沉重的书,上面有一个页码,我可以用RTFM 一般问题 对于大型应用程序中的一个视图,我试图向用户展示一个包含四个主要
View Controller -- Doing what it does.
* UIView -- Used to set a static background.
* UIScrollView -- Sized to the parent view, used for scrolling
* UIView -- Width equal to ScrollView, height is arbitrarily large (1200 in my project)
We shall call him "subScrollView"
* Content
* More Content
我必须在我的ViewController的ViewDidDisplay:方法中对内容视图的大小/位置进行更改,因为过早地进行更改将无法进入实际显示的视图。
我需要的原因是什么?subScrollView是,如果所有我的内容视图都是ScrollView的子视图,则每当发生滚动时,就会出现上述问题—例如,视图出现,表格调整大小,按钮移动,然后用户滚动场景,表格恢复到Interface Builder中给出的大小,然后按钮移回其原始位置
下面是我用来调整内容视图的代码:
WhyEventViewController.h
谢谢你爬下这堵文字墙,谢谢你抽出时间
@interface whyEvenViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *wasteMoreSpaceLabel;
@property (weak, nonatomic) IBOutlet UIButton *aButton;
@property (nonatomic) NSInteger tableViewRowCount;
@end
- (void)viewDidAppear:(BOOL)animated
{
// Here's where we resize and move everything. If we attempt to make these
// changes before this (e.g. in viewDidLoad, viewWillAppear:, or even
// viewDidLayoutSubviews) they get changed back before this view transitions
// onto the screen, be it from a Navigation Bar push, or opening the app.
[super viewDidAppear:animated];
// Get used to this guy. He's going to be helping us resize frames.
CGRect newFrame;
// Set the tableView's frame height to the height of its contentSize which
// so the entire table (no mater how large it is) is visible.
newFrame = self.tableView.frame;
newFrame.size.height = self.tableView.contentSize.height;
self.tableView.frame = newFrame;
// Move the wasteMoreSpaceLabel to just below the tableView
newFrame = self.wasteMoreSpaceLabel.frame;
newFrame.origin.y = self.tableView.frame.origin.y + self.tableView.frame.size.height - 20;
self.wasteMoreSpaceLabel.frame = newFrame;
// Move aButton to just below the wasteMoreSpaceLabel
newFrame = self.aButton.frame;
newFrame.origin.y = self.wasteMoreSpaceLabel.frame.origin.y + self.wasteMoreSpaceLabel.frame.size.height + 8;
self.aButton.frame = newFrame;
// Set the size of the scroll view such that it ends 20 points below aButton.
CGSize newSize = self.scrollView.contentSize;
newSize.height = self.aButton.frame.origin.y + self.aButton.frame.size.height + 20;
self.scrollView.contentSize = newSize;
}