1

ビューに2つのサブビューを追加したUIPageViewControllerがあります.UITapGestureRecognizerを持つ透明なサブビューと、他のサブビューをタップすると下からスライドするいくつかのボタンを持つツールバーです。

編集。これは、viewDidAppear:(BOOL)animated のサブビュー設定です。

CGRect frame;
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice]orientation])){
    frame = CGRectMake(50, 0, 220, 480);
}
else {
    frame = CGRectMake(50, 0, 380, 320);
}
if (!tapView) {
    tapView = [[LSTapView alloc]initWithFrame:frame];
    //[tapView setBackgroundColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:0.4]];
    [self.view addSubview:tapView];
    [tapView release]; 
}
else {
    if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice]orientation])){
        [tapView setFrame:CGRectMake(50, 0, 220, 480)];
        [fontViewController.view setFrame:CGRectMake(0, 480, 320, 92)];
    }
    else {
        [tapView setFrame:CGRectMake(50, 0, 380, 320)];
        [fontViewController.view setFrame:CGRectMake(0, 320, 480, 92)];

    }
}

if (!fontViewController){
    fontViewController = [[LSFontViewController alloc]initWithNibName:@"LSFontView" bundle:nil];
}
if (UIDeviceOrientationIsPortrait([[UIDevice currentDevice]orientation])){
    [fontViewController.view setFrame:CGRectMake(0, 480, 320, 92)];
}
else {
    [fontViewController.view setFrame:CGRectMake(0, 320, 480, 92)];
}

[self.view addSubview:fontViewController.view];

デバイスを回転させずにページを変更すると、すべてが両方の向きで正常に機能します。それにもかかわらず、デバイスを回転させると、これら 2 つのサブビューが消え、前面にないことがわかります。とにかく、これをコードに追加すると:

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    [self.view bringSubviewToFront:tapView];
    [self.view bringSubviewToFront:fontViewController.view];
}

何か奇妙なことが起こります: ページを変更することはもうできません。または、前と次の viewController は正しく読み込まれますが、それらは表示されず、ページは変更されません。

誰かが私に何が起こっているのか説明できますか?

ありがとうございました。L.

4

2 に答える 2

1

次のように UIPageViewController を UIDeviceOrientationDidChangeNotification に登録することで問題を解決しました。

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

そして、この単純なセレクターを追加することにより:

-(void)didChangeOrientation{
    [self.view bringSubviewToFront:tapView];
    [self.view bringSubviewToFront:fontViewController.view];
}

よくわからない理由もありますが、didRotateFromInterfaceOrientation セレクターを追加するだけでデータ ソースがめちゃくちゃになり、奇妙なクラッシュが発生します。

于 2012-08-06T09:12:59.313 に答える
0

あなたの問題は、iOS 5 でデバイスを回転させた後に自動的に呼び出されないという事実に関係しているはずviewWillAppearです。したがって、デバイスを回転させると、サブビューのフレームを再配置するコードが実行されません。これが iOS 5 のバグなのか、iOS 5 の特定のマイナー バージョンのバグなのかはわかりませんが、数週間前にこれを発見し、オートローテーションの存在下でロジックを混乱させました。

これを修正する簡単な試みは次のとおりです。

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
   [self viewWillAppear:NO];
}

これがうまくいくかどうか教えてください。

いずれにせよ、 でビューをインスタンス化しているのは非常に不可解ですviewWillAppear。IMO、そのための適切な場所はviewDidLoad.

私の提案は、サブビュー作成のロジックを でviewDidLoad処理し、ビューの配置のロジックを別のメソッドで処理することです。layoutSubviewsそれを と呼びましょviewDidLoaddidRotateFromInterfaceOrientation

于 2012-08-04T09:50:35.973 に答える