0
votes

I have a full screen UIScrollView to display my image, which employ some codes from PhotoScroller.app from apple sample code. I am little confused on the bounds of a imageView in a scrollView with rotation, and the convertPoint. Any help will be appreciated!

ps. For more detail codes please find in Center of bounds

NSLog in call willRotateToInterfaceOrientation:duration:

2012-05-12 11:35:45.666 imageScrollView frame X and Y are 0.000000 and 0.000000 
2012-05-12 11:35:45.672 imageScrollView frame Width and Height are 320.000000 and 480.000000 
2012-05-12 11:35:45.677 imageScrollView bounds origin X and Y are 0.000000 and 0.000000 
2012-05-12 11:35:45.682 imageScrollView bounds Width and Height are 320.000000 and 480.000000 
2012-05-12 11:35:45.686 imageView frame origin X and Y are 0.000005 and 0.374437
2012-05-12 11:35:45.689 imageView frame size Width and Height are 320.000000 and 479.251129
2012-05-12 11:35:45.693 imageView bounds origin X and Y are 0.000000 and 0.000000
2012-05-12 11:35:45.697 imageView bounds size Width and Height are 641.000000 and 959.999939
2012-05-12 11:35:45.701 boundsCenter X and Y are 160.000000 and 240.000000 
2012-05-12 11:35:45.705 convertPoint origin X and Y are 320.500000 and 479.999969

NSLog in call willAnimateRotationToInterfaceOrientation:duration:

2012-05-12 11:36:05.975 imageScrollView frame X and Y are 0.000000 and 0.000000 
2012-05-12 11:36:05.978 imageScrollView frame Width and Height are 480.000000 and 320.000000 
2012-05-12 11:36:05.983 imageScrollView bounds origin X and Y are 0.000000 and 0.000000 
2012-05-12 11:36:05.987 imageScrollView bounds Width and Height are 480.000000 and 320.000000 
2012-05-12 11:36:05.990 imageView frame origin X and Y are 80.000008 and 0.000017
//I am confused here. Why is the X is 80.000008, and Y is 0.000017, but not (80, -120)?
2012-05-12 11:36:05.994 imageView frame size Width and Height are 320.000000 and 479.251099
2012-05-12 11:36:06.002 imageView bounds origin X and Y are 0.000000 and 0.000000
2012-05-12 11:36:06.006 imageView bounds size Width and Height are 641.000000 and 959.999878
2012-05-12 11:36:06.009 boundsCenter X and Y are 240.000000 and 160.000000 
2012-05-12 11:36:06.014 convertPoint origin X and Y are 320.500000 and 320.499969

About the autoresizing configuration:

actionSheetCoverView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
imageScrollView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
imageView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

The imageview frame origin before rotate (NSLog in willRotateToInterfaceOrientation:duration) is (0, 0) , after rotate (NSLog in the willAnimateRotationToInterfaceOrientation:duration:), i think it should be (80, -120). But it is (80.000008, 0.000017);

2
You do not say what you are confused about and you do not say why you want to get the center of the bounds so it is really hard to help you out here.Michael Frederick
@MichaelFrederick I have update the post, plz check.lu yuan
Is the problem after rotation with scrollView content size?Warif Akhand Rishi
@WarifAkhandRishi The content size is image.size, never changed after the rotation.lu yuan

2 Answers

1
votes

As I explained, it is hard to help you out when you don't say why you are confused or what you are attempting to do.

To get the actual center of the imageView, you can use this:

imageView.center
1
votes

The frame property always returns a calculated value based on the bounds, center, and transform properties of a UIView.

As per Apple's UIView documentation:

If the transform property is not the identity transform, the value of the frame property is undefined and therefore should be ignored.

The problem is that you're reading the frame property at the start of a rotation animation, which means your views will have a non-identity transform value, making their frame values meaningless.

You can log the transform values like so, based on the code from your other question:

NSLog(@"imageScrollView transform %@", NSStringFromCGAffineTransform(self.transform));

NSLog(@"imageView transform %@", NSStringFromCGAffineTransform(imageView.transform));

This will show you the transform property at the time of rotation. If you're not familiar with the Identity Transform, it's [1, 0, 0, 1, 0, 0].

In other words, the reason the frame property is giving you unexpected values is because your view has a transform applied to it, rendering the frame property meaningless.

It's not clear what you're actually trying to achieve, but this other note from the same Apple documentation may be of help:

If the transform property contains a non-identity transform, the value of the frame property is undefined and should not be modified. In that case, you can reposition the view using the center property and adjust the size using the bounds property instead.