我一直在尋找這方面的很多東西,並且找不到任何東西來幫助我。旋轉UIViewController來抵消UIInterfaceOrientation的變化
我有一個UIViewController包含在另一個UIViewController。當父級UIViewController旋轉時,從Portrait到LandscapeLeft說,我想讓它看起來好像孩子沒有旋轉。也就是說。無論父母的方向如何,我都希望孩子擁有與天空一致的方向。如果它有一個在Portrait中直立的UIButton,我希望按鈕的右側在UIInterfaceOrientationLandscapeLeft中「向上」。
這可能嗎?目前,我正在做這樣的嚴重的東西:
-(void) rotate:(UIInterfaceOrientation)fromOrientation: toOr:(UIInterfaceOrientation)toOrientation
{
if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationLandscapeRight))
|| ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationLandscapeLeft)))
{
}
if(((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
|| ((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationPortrait)))
{
}
if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationLandscapeLeft))
|| ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationLandscapeRight)))
{
}
if(((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
|| ((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationPortrait)))
{
}
if(((fromOrientation == UIInterfaceOrientationPortrait) && (toOrientation == UIInterfaceOrientationPortraitUpsideDown))
|| ((fromOrientation == UIInterfaceOrientationPortraitUpsideDown) && (toOrientation == UIInterfaceOrientationPortrait)))
{
}
if(((fromOrientation == UIInterfaceOrientationLandscapeLeft) && (toOrientation == UIInterfaceOrientationLandscapeRight))
|| ((fromOrientation == UIInterfaceOrientationLandscapeRight) && (toOrientation == UIInterfaceOrientationLandscapeLeft)))
{
}
}
這似乎是一個非常好的浪費代碼。此外,我計劃使用CGAffineTransform(如引用此處:http://www.crystalminds.nl/?p=1102),但我很困惑我是否應該改變視圖的尺寸以匹配旋轉後的視圖。
這裏最大的噩夢是你必須跟蹤一個全球「定向」變量。如果你不這樣做,錯覺就會消失,ViewController會旋轉到任何地方。
我真的可以使用一些幫助,謝謝!
感謝Madhup。 當你建議「改變肖像視圖的視圖和子視圖框架」 - 這是我會做一個CGAffineTransform?或者我應該有某種單獨的方式來旋轉UIView/UIViewController?我需要所有元素以相同的方式行事,只是有不同的方向。 另外,你評論的self.view = portraitView是什麼意思?我會從一開始就使用這些方法,但我不知道如何獲得側身UITableView或側向UIButton或類似的東西。 再次感謝! – 2010-03-22 19:43:54
@Peter Hajas:我不執行CGAffine轉換,而是從xib獲取縱向和橫向視圖的幀位置,並相應地更改我的子視圖的框架。 – 2010-03-23 04:16:30
我試圖實現這個方法,但是每當我旋轉模擬器設備時,沒有任何方法被觸發。你知道爲什麼嗎? – singingAtom 2011-05-24 12:34:09