(我的英語不是很好笑)當我改變的UIView的bounds.size.height在frame.origin.y變化
我定義一個UIView對象作爲子視圖,當我改變subview.bounds。 size.height,subview.frame.origin.y改變了,我的代碼有什麼問題嗎?
這裏是我的代碼:
- (IBAction)touch
{
static int i = 1;
NSLog(@"%d: Bounds: %@", i, NSStringFromCGRect(self.subView.bounds));
NSLog(@"%d: Frame: %@", i, NSStringFromCGRect(self.subView.frame));
self.subView.bounds = CGRectMake(0.f, 0.f, self.subView.bounds.size.width, self.subView.bounds.size.height + 50);
NSLog(@"%d: Bounds: %@", i, NSStringFromCGRect(self.subView.bounds));
NSLog(@"%d: Frame: %@", i, NSStringFromCGRect(self.subView.frame));
i++;
}
系統輸出:
2011-12-23 12:11:29.316 Angry[7959:f803] 1: Bounds: {{0, 0}, {320, 100}}
2011-12-23 12:11:29.318 Angry[7959:f803] 1: Frame: {{0, 0}, {320, 100}}
2011-12-23 12:11:29.319 Angry[7959:f803] 1: Bounds: {{0, 0}, {320, 150}}
2011-12-23 12:11:29.320 Angry[7959:f803] 1: Frame: {{0, -25}, {320, 150}}
2011-12-23 12:11:30.920 Angry[7959:f803] 2: Bounds: {{0, 0}, {320, 150}}
2011-12-23 12:11:30.921 Angry[7959:f803] 2: Frame: {{0, -25}, {320, 150}}
2011-12-23 12:11:30.922 Angry[7959:f803] 2: Bounds: {{0, 0}, {320, 200}}
2011-12-23 12:11:30.923 Angry[7959:f803] 2: Frame: {{0, -50}, {320, 200}}
2011-12-23 12:11:32.080 Angry[7959:f803] 3: Bounds: {{0, 0}, {320, 200}}
2011-12-23 12:11:32.082 Angry[7959:f803] 3: Frame: {{0, -50}, {320, 200}}
2011-12-23 12:11:32.083 Angry[7959:f803] 3: Bounds: {{0, 0}, {320, 250}}
2011-12-23 12:11:32.084 Angry[7959:f803] 3: Frame: {{0, -75}, {320, 250}}
是的,你是對的。但UIView.bounds.size.height改變了,UIView.frame.origin.y也改變了。這似乎很奇怪。 Apple文檔沒有關於此的定義。 – LekHo 2011-12-23 06:10:17
以下是文檔鏈接:https://developer.apple.com/library/ios/documentation/windowsviews/conceptual/viewpg_iphoneos/WindowsandViews/WindowsandViews.html – cyrilchampier 2014-09-10 09:48:36