0

![メインギャラリービューの2番目のビュー] [1]こんにちは、デバイスが横向きのときに新しいビューコントローラーを呼び出そうとしています。スクロールビューの画像ギャラリーです。別の位置に画像ギャラリーを表示したいのですが、方法がわかりません。ストーリーボードでXcode4.3を使用しているので、古いバージョンとは少し異なります。

ご協力ありがとうございました。![これは、横向きのコードなしでどのように見えるか、スクロールが消える][2]それで私は別のビューを呼んでいます

ダン!画像を投稿することはできません

4

2 に答える 2

1

絵コンテで横向きのビューを作成します。インスペクタに、LandscapeView などの識別子を追加します。次に、元のビュー コントローラーで、ランドスケープ ビューのビュー コントローラーのヘッダー ファイルをインポートします。

#import "LandscapeViewController.h" //Change to whatever your file is called

次のメソッドを次のように変更します。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    LandscapeViewController *landscapeView = [self.storyboard instantiateViewControllerWithIdentifier:@"LandscapeView"]; //change LandscapeViewController to the correct name and change LandscapeView to the correct identifier
    landscapeView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; //Or whatever transition you want

    [self presentModalViewController:landscapeView animated:NO];
    return YES;
}

次に、横向きビューのビュー コントローラーで、同じメソッドを次のように変更します。

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    [self dismissModalViewControllerAnimated:NO];
    return YES;
}
于 2012-06-07T18:29:02.633 に答える
0

次を使用して方向を検出できます。

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(detectOrientation) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

次に、変更を検出したときに新しい ViewController にセグエする関数を記述できます。

-(void) detectOrientation {

    if (([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft) || ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)) {
    {
        if(!self->wasInLandscape)
        {
            [self performSegueWithIdentifier:@"Landscape Segue" sender:self];
            self->wasInLandscape = YES;
        }


    } else if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown) 
    {

        if(self->wasInLandscape)
        {
            [self dismissModalViewControllerAnimated:NO];
            self->wasInLandscape = NO;
        }

    }   
}

これで、セグエをアニメーションなしのモーダル セグエとして設定したので、切り替えたときにそれ自体が表示されます。はwasInLandscape BOOL、既に現在の位置にいるときに、セグエを閉じたり実行したりしないようにするために使用されます。

于 2012-06-07T18:27:56.623 に答える