0

保存しようとしたときにアイテムエントリの名前フィールドに値が入力されていない場合にUIAlertViewをポップアップするビューがあります。代わりに、独自のカスタムアラートビューを表示したかったのです。私はそれをxibでロードします:

- (void)enterNameAlert {

    NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"AddNameAlertView" owner:self options:nil];
    enterNameAlertView = [subviewArray objectAtIndex:0];
    enterNameAlertView.frame = CGRectMake(232, 417, 303, 171);
    enterNameAlertView.alpha = 0.0;
    [self.view addSubview:enterNameAlertView];
    [self.view bringSubviewToFront:enterNameAlertView];

    //fade view in
    [UIView animateWithDuration:.50f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void) {

        enterNameAlertView.alpha = 1.0;

    } completion:NULL];

    [UIView commitAnimations];

}

ただし、アラートが表示されている間は、ビュー上の他のすべての要素をクリックすることができます。理想的には、alertviewをモーダルにしたいです。ハックとして、アラートビューが表示されている間は他のすべての要素にxxxx.enabled = NOを設定し、アラートで[OK]を押すとそれらをxxxx.enabled=YESに戻します。

self.viewへのすべてのタッチをキャンセルするより良い方法が必要ですが、self.enterNameAlertViewへのタッチはキャンセルしないでください。

self.view.userInteractionEnabled = NOを実行すると、self.viewおよびself.enterNameAlertViewへのすべてのタッチがキャンセルされます。

何か案は?

4

2 に答える 2

0

あなたの問題の解決策は、カスタムアラートビューと元のビューの間にもう1つのビューを導入する必要があることだと思います。アラートが発生したら、そのビューをself.viewに表示し、非表示(または削除)する必要があります。警告は却下されました、私はすでにこれをしました、そしてそれは私にとって魅力のように働きます。これがあなたにも役立つことを願っています:)

于 2012-10-10T06:58:32.657 に答える
0

とった。インタラクションを有効にしてUIScrollViewを使用しました。これにより、カスタムアラートビューの外側からのタッチが下のメインビューに渡されるのを防ぎます。

- (void)enterNameAlert {

    //pop a UIScrollView behind the alert so that the user can't touch the controls behind it
    shadowScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
    shadowScrollView.userInteractionEnabled = YES;
    shadowScrollView.backgroundColor = [UIColor blackColor];
    shadowScrollView.alpha = 0.0;
    [self.view addSubview:shadowScrollView];
    [self.view bringSubviewToFront:shadowScrollView];

    //put the alertview in front of the disabled view to make it act like a modal view
    NSArray *subviewArray = [[NSBundle mainBundle] loadNibNamed:@"AddNameAlertView" owner:self options:nil];
    enterNameAlertView = [subviewArray objectAtIndex:0];
    enterNameAlertView.frame = CGRectMake(232, 417, 303, 171);
    enterNameAlertView.alpha = 0.0;
    [self.view addSubview:enterNameAlertView];
    [self.view bringSubviewToFront:enterNameAlertView];

    //animate view in
    [UIView animateWithDuration:.50f delay:0.0f options:UIViewAnimationOptionCurveEaseOut animations:^(void) {

        shadowScrollView.alpha = .6;
        enterNameAlertView.alpha = 1.0;

    } completion:NULL];

    [UIView commitAnimations];

}
于 2012-10-11T03:06:17.607 に答える