0
我有一個iPad應用程序,有2個視圖,每個都有自己的視圖控制器。蘋果表示他們建議iPad應用程序能夠全方位旋轉。我用這個技術在我的故事板中的元素定位在旋轉的變化:iOS 5多故事板旋轉
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
//[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft)
{
studentNumberButton.frame = CGRectMake(30, 1, 158, 155);
studentNumberLabel.frame = CGRectMake(173, 57, 347, 43);
studentLabel.frame = CGRectMake(528, 56, 67, 43);
// Other code goes below...
我這樣做是爲每個視圖,併爲所有旋轉工作正常。然而,當我說,讓View Controller 1上的iPad處於橫向狀態並按下一個按鈕以顯示View Controller 2時,View Controller 2出現的很好,但處於肖像模式時,問題就出現了。如果我處於View Controller 2的橫向模式並轉到View Controller 1,也會發生同樣的情況。如果我處於縱向模式,則兩個視圖都可以正常工作。
我如何做到這一點,當我切換視圖時,視圖知道設備在哪個方向並相應旋轉?
謝謝!