6

背景:アプリには家に帰る機能があります。ホームビューポートレートのみをサポートします。通常より少し強く振ると、現在のビューが回転し始めますが(これは問題ありません)、その後、揺れを検出して、ホームビューに対してpopViewControlllerを実行します。これを行うと、ナビゲーションコントローラーが正常に読み込まれますが、(ホームコンテンツ)の下のビューがバーの後ろに読み込まれ、引き伸ばされます(基本的に、ナビゲーションバーの下に読み込まれるため、引き伸ばされます)

戻るボタンは、これを横向きから縦向きにうまく処理します(トランジションの途中ではないため)

ナビゲーションバーの下にビューをロードせずにルートビューコントローラーに戻ることができるように、(シェイクからの)この方向の変更をどのように処理する必要がありますか?

編集:何が起こっているのかというと、コンテンツはそれがロードするビュー全体を持っていると考えているので、その上にナビゲーションバーがあることに気付かずに、画面全体を占めるようにそれ自体を伸ばします。読み込んでいる画像が引き伸ばされているのでわかります

50の賞金を追加しました。

編集これが私がシェイクとポッピングを検出する方法です

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{

    if ( event.subtype == UIEventSubtypeMotionShake )
    {

            UINavigationController *navController = self.navigationController;

            [[self retain] autorelease];
            HomeViewController *home = [[HomeViewController alloc]init];
            [navController popViewControllerAnimated:YES];

            home.title =@"Home View Controller";
            [home release];     
        }

    if ( [super respondsToSelector:@selector(motionEnded:withEvent:)] )
        [super motionEnded:motion withEvent:event];
}

これが私のアプリデリゲートです:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    navController = [[UINavigationController alloc]init];
    [self.window addSubview:navController.view];

    HomeViewController *home = [[HomeViewController alloc]init];
    [[self home] setFrame:[[UIScreen mainScreen] applicationFrame]];

ここにモックアップを含めます。

通常のビュー:

通常のビュー

シェイク/ポップ後のストレッチビュー:

ストレッチド

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 
{}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}
4

4 に答える 4

2

ホームビューコントローラーのxibで、ビューのに移動し、inspectorトップバーをナビゲーションバーとして設定します。ビューでロードセットを実行しましたself.navigationBarHidden = NO;...

注:投稿したコードには多くの問題がありますが、いずれも方向の問題を引き起こしません...実際、このメソッドで必要なコードはこれだけのようです。

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    if (event.subtype == UIEventSubtypeMotionShake)
    {
        [navController popViewControllerAnimated:YES];
    }
}

したがって、このコードも変更することをお勧めします。

于 2011-07-25T10:10:22.403 に答える
2

[[UIApplication sharedApplication] setStatusBarOrientation: UIInterfaceOrientationPortrait animated:YES];ホームビューコントローラで呼び出してみましたか?揺れを検出した場所にこれを配置することもできます。

于 2011-07-13T22:22:34.830 に答える
2

ナビゲーションバーのアンダーラップでこの問題に遭遇しました。原因はわかりませんが、次のように電話することで回避できます。

[[self loadingView] setFrame:[[UIScreen mainScreen] applicationFrame]];

問題ビューがアプリケーションデリゲートのウィンドウに追加された後。

于 2011-07-25T22:59:16.480 に答える
2

私はあなたのコードに少し戸惑っているので、最初から始めることを本当にお勧めします。Lukyaが述べたように、HomeViewControllerを再作成する理由はありません。「[[自己保持]自動リリース];」にも困惑しています。少し。他の場所で何か間違ったことをしているのでない限り、それは必要ないはずです。

だから私はこれから始めます...application:didFinishLaunchingWithOptionsで:次のようなことをします:

    -(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {{
        HomeViewController * home = [[[HomeViewController alloc] init] autorelease];
        UINavigationController * navController = [[[UINavigationController alloc] initWithRootViewController:home] autorelease];
        [self.window addSubview:navController.view];
    }

ウィンドウはnavコントローラーを保持し、navコントローラーはHomeViewControllerを保持します。

次に、motionEnded:withEventで次のようにします。

    -(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {{
        if(event.subtype == UIEventSubtypeMotionShake)
        {{
            [self.navigationController popViewControllerAnimated:YES];
        }
    }

それはそれであるはずです。

それがうまくいかない場合は、他の情報を提供できますか?たとえば、HomeViewControllerはshouldAutorotateToInterfaceOrientationに実装(およびYESを返す)しますか?もしそうなら、あなたの最初の行が「ホームビューはポートレートのみをサポートしている」と言っているので回転しないようにあなたはノーを返すことができますか?

willRotateToInterfaceOrientation:duration:編集:との例didRotateFromInterfaceOrientation:

揺れを検出しているコントローラーのヘッダーにブール値を追加します。

    BOOL isRotating;

実装ファイルに、オーバーライドする2つのUIViewControllerメソッドを追加します。次のようになります。

    -(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
        isRotating = YES;
    }

    -(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
        [スーパーdidRotateFromInterfaceOrientation:fromInterfaceOrientation];
        isRotating = NO;
    }

次に、イベントハンドラーに対して次のようなことを行います。

    -(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
    {{
        if(event.subtype == UIEventSubtypeMotionShake &&!isRotating)
        {{
            [self.navigationController popViewControllerAnimated:YES];
        }
    }
于 2011-07-26T23:31:40.233 に答える