简体   繁体   中英

ScrollView doesn't work in landscape orientation

I am developing in Objective-C . I am using the following code for scrollView , and it works fine in Portrait orientation.

- (void)viewDidLayoutSubviews
{
   UIScrollView *scrollView = self.scrollview;
   [scrollView setContentSize:CGSizeMake(320.0,3100.0)];
}

But the view does not slide down when I change to landscape orientation.

Am i missing something?

[scrollView setContentSize:CGSizeMake(320.0,3100.0)];

In this, 320 used for Width.. When you are trying for landscape orientation. Then please increase size for width..
Please check it with more than 320 (Minimum Screeen Width).
3.5 inch - 480 & 4 inch - 568

[scrollView setContentSize:CGSizeMake(SCREEN_WIDTH + YOUR_EXTRA_SIZE,3100.0)];

Hopefully, it will help you.
Thanks.

- (void)viewWillAppear:(BOOL)animated
{
   UIScrollView *scrollView = self.scrollview;
   [scrollView setContentSize:CGSizeMake(320.0,3100.0)];
}

Scrollview always loaded in portrait mode in viewDidLoad/loadView method, so what ever adjustment you like to made you have to do those changes in viewWillAppear/viewDidAppear methods.

When Device get rotate didRotateFromInterfaceOrientation method get called, so I would suggest to change the ScrollView Contant size this way

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    self.scrollView.contentSize = self.contentView.bounds.size;
}

Note : Make sure your have UIScrollView and UIView in your layout

UIScrollView is scrollView and
UIView is contentView

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM