Question

I use the view-based template to create my app, and return YES in shouldAutorotateToInterfaceOrientation to support auto-rotation. Next, I add a square testView_ object (with default auto-resizing setting), and rotate it at initialization:

- (void)viewDidLoad {
[super viewDidLoad];
    testView_.transform = CGAffineTransformMakeRotation(0.1);
}

Now, whenever I rotate the iPhone, the testView_ will be distorted. What is the reason, and how to correct it? The testView_ width and height are changed after each time I rotate the iPhone, even though it shouldn't be autoresized (and this only happens if the testView_ is rotated initially).

Was it helpful?

Solution

Well, finally my solution is to do

testView_.transform = CGAffineTransformIdentity;

in willRotateToInterfaceOrientation method, then redo

testView_.transform = CGAffineTransformMakeRotation(0.1);

in didRotateFromInterfaceOrientation. This helps solving distortion.

It is more complicated if there are also translation, scaling... involved, but the idea is there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top