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

Community
  • 1
  • 1
Julien
  • 13
  • 2

1 Answers1

1

That's probably because in viewWillAppear the subviews frames are not completly initialized yet. Instead, try to call your method in this method of your viewController:

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

See more information here: ScrollView created in storyboard initialized with frame 0,0,0,0

Community
  • 1
  • 1
Lucas Eduardo
  • 11,525
  • 5
  • 44
  • 49
  • It's working! Super! thank you so much for the fast response! I had checked the forum before posting, but apparently didn't use the right search terms... – Julien Aug 05 '13 at 06:04
  • I glad it worked for you. Please, upvote and accept the Answer in order to close your question and remove it from the Unanswered area. – Lucas Eduardo Aug 05 '13 at 12:59
  • Hi, I just have another question, related to this modification to my code. When I do this, I notice I can no longer modify the frame of my main view. After I do my setup, it forces me to perform another `[self loadSubviews]`method, which is practically an undo of my whole work setup... Any idea on how to solve this? The whole point is that I want to change the size of my `UITextView`depending if I'm on a 3.5" or 4" screen... Should I turn of autolayout for this, or is there another way? – Julien Aug 05 '13 at 18:38
  • You should try to use autolayout for this purpose (resizing depends of the screen), and never mess with the main view's frame. Try another approach. If you still has more doubts about what you are trying to do with your UITextView, it will be better create a whole new question! – Lucas Eduardo Aug 05 '13 at 18:45