21

iOS 7 でバグと思われる問題が発生したか、適切な対応をしていません。ModalPresentationStyle を使用して、iPad でポップオーバーとして表示される modalViewController があります。また、標準サイズではなく、カスタムサイズです。コードは次のとおりです。

myViewController *myVC = [[myViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:myVC];
[nav setModalPresentationStyle:UIModalPresentationFormSheet];
[nav setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal];
[self presentViewController:nav animated:YES completion:nil];
nav.view.superview.bounds = CGRectMake(0, 0, 320, 465);

iOS 6 では問題なく動作していますが、iOS 7 では中央に配置されていません。しかし、ModalTransitionStyle を UIModalTransitionStyleCrossDissolve に設定すると、正常に動作します。ただし、このモードのみ。多分誰かがこれにつまずいて、それを修正する方法を知っていますか? 私はディゾルブ効果の大ファンではありません。ありがとうございました。

4

6 に答える 6

39

私も同じ問題を抱えていました。ここにある別のアプローチを使用してこれを解決しました。

このソリューションが提案するのは、メソッドを使用することです(void)viewWillLayoutSubviews

したがって、@Manuel M. の場合は、GeneralSettingsViewController以下のコードを追加します。

// GeneralSettingsViewController
- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    self.view.superview.bounds = CGRectMake(0, 0, 497, 375);
}

そして、このコードはもう必要ありません:

self.generalSettingsVC.view.superview.frame = CGRectMake(0, 0, 497, 375);
self.generalSettingsVC.view.superview.center = self.view.center;

@titicaca の場合、このコントローラーでテストしていませんが、メソッドを拡張して上書きするUINavigationController同じソリューションを試すことができます。UINavigationControllerviewWillLayoutSubviews

[編集]

@titicacaの場合、新しいプロジェクトで試してみましたが、うまくいきました。私がしたことは、次のようCustomNavigationControllerにオーバーライドするカスタム ナビゲーション ビュー コントローラーを用意することでした。viewWillLayoutSubviews

- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    self.view.superview.bounds = CGRectMake(0, 0, 330, 284);
}

次に、を表示するView Controllerは、次のCustomNavigationControllerようなコードを実行する必要があります。

UIViewController *myVC = [[UIViewController alloc] init];
[myVC.view setBackgroundColor:[UIColor redColor]];

CustomNavigationController *nav = [[CustomNavigationController alloc] initWithRootViewController:myVC];
[nav setModalPresentationStyle:UIModalPresentationFormSheet];
[nav setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal];

[self presentViewController:nav animated:YES completion:nil];

self.view.superview.bounds = CGRectMake(0, 0, 330, 284);ただし、の次元が偶数であることを確認する必要があります。そうしないと、内部のテキストがぼやけてしまいます。

于 2013-09-26T11:22:32.500 に答える
5

私にとっての問題は、提示されたView ControllerのbecomeFirstResponderテキストフィールドを呼び出すことでした。viewDidAppear現在はバグのようです。解決策は、それを単純にラップすることでしたdispatch_async:

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.userNameTextField becomeFirstResponder];
    });
}
于 2014-03-21T17:27:39.823 に答える
3

を設定しても、古いカスタム モーダル プレゼンテーション スタイルでfromsheet動作するメソッドがiOS <=7ありますcustom height and width

この方法は、将来の新しいバージョンでは機能しない可能性があることに注意してください

- (void) hackModalSheetSize:(CGSize) aSize ofVC:(UIViewController *) aController;
{

    void (^formSheetBlock) (void) = ^{
        int preferredWidth = aSize.width;
        int preferredHeight = aSize.height;

        CGRect frame = CGRectMake((int) 1024/2 - preferredWidth/2,
                                  (int) 768/2 - preferredHeight/2,
                                  preferredWidth, preferredHeight);
        aController.view.superview.frame = frame;
        if([aController respondsToSelector:@selector(edgesForExtendedLayout)]) { //ios7
            aController.view.superview.backgroundColor = [UIColor clearColor];
        } else { // < ios7
            UIImageView *backgroundView = [aController.view.superview.subviews objectAtIndex:0];
            [backgroundView removeFromSuperview];
        }
    };

    //on ios < 7 the animation would be not as smooth as on the older versions so do it immediately
    if(![self respondsToSelector:@selector(edgesForExtendedLayout)]) {
        formSheetBlock();
        return;
    }

    double delayInSeconds = .05;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);

    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        formSheetBlock();
    });
}
于 2013-10-02T09:51:01.317 に答える
3

上記の解決策は私にはうまくいきませんでした。私は以下を使用しました:

      UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:theViewController];
      navigationController.modalPresentationStyle=UIModalPresentationFormSheet;
      [self presentViewController:navigationController animated:YES completion:nil];
      if([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPhone){
            navigationController.view.superview.frame = CGRectMake(0, 0, 320, 544);
            navigationController.view.frame =CGRectMake(108, 0, 320, 544);
            navigationController.view.superview.backgroundColor=[UIColor clearColor];
      }
于 2014-03-22T06:47:32.977 に答える