1

I'm a newbie at objective C programming, so please excuse me if this question has a trivial answer. I wanted to create a UIScrollview that's larger than the screen size. In order to be able to place all the subviews appropriately inside that main view, I tried the trick suggested in this post. In this large UIScrollView I have several subviews, such as a ToolbarView, UITextView, UIButtons and container view. During startup I start setupView to update the frame size of the textview based on the actual screen size. I managed to do this in a separate nib file without too much trouble, but when I try this in the storyboard, a strange thing happens: the UITextView (paperlist) gets initialized and a text is set to it. However, when I try to get the frame size it results in a CGRectwith zero size.

hereunder a snippet of the code I wrote:

- (void)viewWillAppear:(BOOL)animated
{
[super viewDidLoad];
[self setupView];
// Do any additional setup after loading the view.
}


#pragma mark update the view
- (void)setupView {
// first update the paperlist height in function of the screen size of the device used
CGFloat statusBarHeight = [[UIApplication sharedApplication] statusBarFrame].size.height;

CGRect newMainFrame = self.view.frame;
CGRect newPaperlistFrame = self.paperlist.frame;
newPaperlistFrame.size.height = [UIScreen mainScreen].bounds.size.height - KEYBOARD_LOWERBORDER - self.mainToolbar.bounds.size.height - statusBarHeight;

newMainFrame.size.height = self.mainToolbar.bounds.size.height + newPaperlistFrame.size.height + self.fullKeyboardView.frame.size.height;

self.view.frame = newMainFrame;
self.paperlist.frame = newPaperlistFrame;
}

Can anybody help??

thanks in advance!

Julien

4

1 回答 1

1

这可能是因为在 viewWillAppear 中,子视图框架尚未完全初始化。相反,请尝试在 viewController 的此方法中调用您的方法:

-(void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    [self setupView];
}

在此处查看更多信息:在使用帧 0,0,0,0 初始化的情节提要中创建的 ScrollView

于 2013-08-04T19:17:13.523 回答