2

楽しみのためだけにアプリを作成していますが、1つの画面で横向きにしたい場合は縦向きのままにするという事実を除いて、うまく機能しているようです。ロード時に自動的に横向きに回転するようにするにはどうすればよいですか? 私はすでにこれを試しました:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);   
}

しかし、これはうまくいかなかったようです。デバイスを回転させたときにのみ、ビューが回転し、横向きのままになりますが、ユーザーがデバイスを回転させて縦向きにすることなく、ロードするとすぐに実行できるようにしたいと考えています。不足しているものはありますか?助けてくれてありがとう!アプリからさらに多くのコードが必要な場合は、喜んで共有させていただきます。

4

3 に答える 3

3

これを viewDidLoad メソッドと shouldautorotate メソッドに追加します。

 [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
 [[self view] setBounds:CGRectMake(0, 0, 480, 320)];
 [[self view] setCenter:CGPointMake(160, 240)];
 [[self view] setTransform:CGAffineTransformMakeRotation(M_PI / 2)];
于 2012-06-18T01:39:53.720 に答える
0

このコードを試してください

@interface UIViewController(ESUtils)
    -(void)changeToPortrait;
@end

@implementation UIViewController(ESUtils)
-(void)changeToPortrait
{
    //for will call a shouldAutorotateToInterfaceOrientation func
    UIViewController *view = [[UIViewController alloc] init];
    [self presentModalViewController:view animated:NO];
    [self dismissModalViewControllerAnimated:NO];
    [view release];
}

@end
于 2012-06-18T02:18:23.997 に答える
0

やりたいことは2つ、

最初にインターフェイスビルダーで、ランドスケープで必要なビューに移動し、向きがランドスケープに設定されていることを確認します (推定されている場合は、親の向きになります)。これは、プロパティ インスペクターの 4 番目のタブにある [シミュレートされたメトリック] の下にあります。

次に、そのビューには投稿したコードが必要です

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight ) || (interfaceOrientation == UIInterfaceOrientationLandscapeLeft);   
}
于 2012-06-18T02:23:12.263 に答える