Chris G.
Chris G.

Reputation: 25974

iphone UISCrollView

Using a UIScrollView with a view containing som textviews and button. In viewDidLoad setting:

_myscrolview.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);

I looks fine in poratraite but in landscape I am unable to scroll to the top for typing in textViews?

Tried setting in "didRotateFromInterfaceOrientation"

_myscrolview.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height);

With or without "didRotateFromInterfaceOrientation"... it only scrolls a bit, but unable to get to the top?

Thanks Regards Christian

Upvotes: 0

Views: 285

Answers (1)

yuxhuang
yuxhuang

Reputation: 5389

Your _myscrolview.frame is changed due to the device rotation.

_myscrolview.frame = self.view.bounds;

And every subview inside _myscrolview probably needs to be re-oriented as well, Their width and height may need to be set to the landscape width.

After sub views inside _myscrolview is resized, you can then calculate the contentSize by:

CGRect contentRect = CGRectZero;

for (UIView *oneView in _myscrolview.subviews) {
  contentRect = CGRectUnion(contentRect, oneView.frame);
}

_myscrolview.contentSize = contentRect.size;

Upvotes: 1

Related Questions