ContentOffset in UIScrollView after rotating iPhone

I have UIImageViewin UIScrollView, and I have some problems with the property contentOffset. Using an Apple link, this is defined as:

contentOffset : the point at which the start of the content view is offset from the start of the scroll.

For example, if the image is in the upper left corner of the screen, as shown below, then the contentOffset will be (0,0):

   _________
   |IMG    |
   |IMG    |
   |       |
   |       |
   |       |
   |       |
   ---------

To rotate the device, I have the following setting:

 scrollView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
       UIViewAutoresizingFlexibleHeight);

 imageView.autoresizingMask = (UIViewAutoresizingFlexibleWidth |
       UIViewAutoresizingFlexibleHeight);

 imageView.contentMode = UIViewContentModeCenter;  
    scrollView.contentMode = UIViewContentModeCenter;

This will make everything rotate around the center of the screen. After turning the screen, the screen will look like this:

    ______________
    |       IMG  |
    |       IMG  |
    |            |
    --------------

, contentOffset, (0,0). ( UIImage , contentOffset , .)

UIImage . contentOffset , .

self.view.transform scrollView.transform, .

+5
1

:

scrollView.autoresizingMask =(UIViewAutoresizingFlexibleWidth 
                                     | UIViewAutoresizingFlexibleHeight);

scrollView.contentMode = UIViewContentModeTopRight;

UIViewContentModeTopRight (0,0), . , UIViewContentModeCenter,

    scrollView.contentOffset = fix(sv.contentOffset, currentOrientation, goalOrientation);

willAnimateRotationToInterfaceOrientation. fix -

CGPoint fix(CGPoint offset, UIInterfaceOrientation currentOrientation, UIInterfaceOrientation goalOrientation) {

CGFloat xx = offset.x;
CGFloat yy = offset.y;

CGPoint result;

if (UIInterfaceOrientationIsLandscape(currentOrientation)) {

    if (UIInterfaceOrientationIsLandscape(goalOrientation)) {
        // landscape -> landscape
        result = CGPointMake(xx, yy);
    } else {
        // landscape -> portrait
        result = CGPointMake(xx+80, yy-80);
    }
} else {
    if (UIInterfaceOrientationIsLandscape(goalOrientation)) {
        // portrait -> landscape
        result = CGPointMake(xx-80, yy+80);
    } else {
        // portrait -> portrait
        result = CGPointMake(xx, yy);
    }
}
return result;
}

scrollview , , (0,0).

+3

All Articles