Alex Rivera | Logout

UIScrollView disable scrolling while rotating on iPhone/iPad

Asked 2010-11-08T12:52:47.577
21

I am using UIScrollView and an image in it as paging one image per page. I have a problem while rotating the iPhone

When I rotate the iPhone then scrollViewDidScroll (Scroll view delegate method) is calling. Due to this, my paging is disturbed and the page number changes.

What is the solution?

Edit
Report

1 Answer

0

My task is to allow scrolling the landscape. The design is for portait. I came up with an idea to add a ScrollView to components, or in "Embed in Scroll View" in Interface Builder. I have expected it will work, but no. I am using Xcode 4.4, iOS 5.1, (office project need support for 4.2 too), but the problem is the same.

In Stack Overflow question iPhone SDK: UIScrollView does not scroll there is one row which solve a problem.

Other try is in Stack Overflow question iOS - UIScrollView is not working (it doesn't scroll at all - the image stays fixed), and this helped me, combined with other, so here is my portait-to-scrollable landscape code:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromOrientation
{ 
    if( UIInterfaceOrientationIsPortrait( [[UIApplication sharedApplication] statusBarOrientation] ) ){
        scrollView.contentSize = portaitScrollSize;
    }
    else{//statusbar is Landscape
        scrollView.contentSize = landscapeScrollSize;
    }    
}

The scrollView in bound to an iVar view in Interface Builder. portaitScrollSize and landscapeScrollSize are private variables. They are initialized and doesn't change. In my.h file:

IBOutlet UIScrollView *scrollView;

In my.m file:

CGSize portaitScrollSize, landscapeScrollSize;

...

portaitScrollSize = CGSizeMake(320,440);
landscapeScrollSize = CGSizeMake(480,480);

I hope it will help somebod

answered 2012-08-26T15:27:42.987

Your Answer