創建一個正方形的UIView對象testView_,並添加這個在viewDidLoad中:在iPhone旋轉後的UIView框架的怪異的行爲
- (void)viewDidLoad {
[super viewDidLoad];
CGRect initialRect = testView_.frame;
NSLog(@"before rotation: w %f h %f x %f y %f", initialRect.size.width, initialRect.size.height, initialRect.origin.x, initialRect.origin.y);
testView_.transform = CGAffineTransformMakeRotation(0.1);
NSLog(@"after rotation: w %f, h %f, x %f, y %f", testView_.frame.size.width, testView_.frame.size.height, testView_.frame.origin.x, testView_.frame.origin.y);
testView_.frame = initialRect;
NSLog(@"reassign: w %f, h %f, x %f, y %f", testView_.frame.size.width, testView_.frame.size.height, testView_.frame.origin.x, testView_.frame.origin.y);
}
我收到此控制檯:
2011-04-27 12:30:32.492 Test[31890:207] before rotation: w 100.000000 h 100.000000 x 20.000000 y 20.000000
2011-04-27 12:30:32.494 Test[31890:207] after rotation: w 109.483757, h 109.483757, x 15.258121, y 15.258121
2011-04-27 12:30:32.495 Test[31890:207] reassign: w 117.873589, h 100.000000, x 11.063205, y 20.000000
我做不到找出幀值這一變化背後的邏輯,尤其是最後一個。任何人都可以啓發我嗎?謝謝。
我不完全確定這個答案。所以我把它作爲一個評論。當我們旋轉視圖,說B,這是A的子視圖,只有B的變換得到改變。根據父視圖中的一個位置來考慮框架,即B在A中的位置。因此,當我們旋轉B時,在A中變換的總平方空間(在A變換中計算)B增加。這是第二個日誌的原因..現在第三你強制給B的原始幀,但旋轉B現在的尺寸大於原始尺寸,這迫使parentView A通過只保持一個方向(y和高度/ x和寬度)自動調整B 。 – Krishnabhadra 2011-04-27 11:01:38
雖然..我很想知道.. – Krishnabhadra 2011-04-27 11:01:54
你沒有回答...太壞.. – Krishnabhadra 2011-04-28 03:06:19