UIInterfaceOrientationで打ち消し変化に回しのUIViewController
-
21-09-2019 - |
質問
私はこの上で多くのことを検索してきた、と私を助けるために何かを見つけることができません。
私はのUIViewControllerは、別のUIViewController内に含まれています。親のUIViewControllerの回転は、LandscapeLeftに肖像画から言うとき、私は子供が回転しなかったかのようにそれが見えるようにしたいです。それは言うことです。私は子供に関係なく、親の方向の空に同じ方向を持っていると思います。それは肖像画で直立だ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は何に回転させてます。
私は本当にこの上でいくつかの助けを使用することができ、感謝!
解決
あなたができる最善のことは、ウルインターフェイスの向きに応じて、あなたのサブビューのフレームのフレームを変更することです。あなたが好きそれを行うことができます:
#pragma mark -
#pragma mark InterfaceOrientationMethods
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown || interfaceOrientation == UIInterfaceOrientationLandscapeRight || interfaceOrientation == UIInterfaceOrientationLandscapeLeft);
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
if(toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
//self.view = portraitView;
[self changeTheViewToPortrait:YES andDuration:duration];
}
else if(toInterfaceOrientation == UIInterfaceOrientationLandscapeRight || toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
//self.view = landscapeView;
[self changeTheViewToPortrait:NO andDuration:duration];
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------------------
- (void) changeTheViewToPortrait:(BOOL)portrait andDuration:(NSTimeInterval)duration{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
if(portrait){
//change the view and subview frames for the portrait view
}
else{
//change the view and subview frames for the landscape view
}
[UIView commitAnimations];
}
希望このことができます。
他のヒント
私は何かを実現。..さんは、(あなたのビューコントローラに他のビューコントローラのサブビューを追加した場合のように)私たちのプロジェクトはのViewControllerの複数の層を持っているとしましょう。
willRotateToInterfaceOrientation:持続方法は、ViewControllerを...
の第二層のために呼び出されることはありません 私は私の一番上の層からの私の第二層・ビュー・コントローラを初期化した後willRotateToInterfaceOrientationときので、私は何をやったことだった、そして:デュレーション方法が一番上の層の上に呼ばれて、私はwillRotateToInterfaceOrientationを呼び出します:第二層・ビュー・コントローラのための期間として、うまく