开发者

Autorotation distorts a rotated view in iPhone

开发者 https://www.devze.com 2023-03-01 12:49 出处:网络
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 set

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, whe开发者_StackOverflow社区never 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).


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号