我有以下代碼:中心子視圖中ParentView在Objective-C
UIView *parentView = [[UIView alloc] init];
parentView.frame = CGRectMake(0, 0, 100, 100);
parentView.center = self.view.center;
parentView.backgroundColor = [UIColor greenColor];
UIView *subView = [[UIView alloc] init];
subView.backgroundColor = [UIColor redColor];
subView.frame = CGRectMake(0, 0, 50, 50);
subView.center = parentView.center;
[parentView addSubview:subView];
[self.view addSubview:parentView];
將會產生以下結果:
爲什麼是綠色的觀點並不爲中心的紅色視圖因爲他們有相同的中心?
嘗試打印查看和檢查的框架。設置中心後。 –
他們共享相同的確切中心。我印刷的價值觀,他們是一樣的。 –
這是你的問題。現在你明白了什麼是問題。 :) –