3

私が開発しているアプリは、ポートレート モードのみをサポートしています。ただし、iOS8 では、非推奨になっUIAlertViewた がランドスケープになり、その他の小さな問題が発生する可能性があります。これを修正するためにUIAlertController、試してみることにしました。それは機能しますが、まだ少し面倒な新しい問題があります。アラートはランドスケープにはなりませんが、パララックス モーションが特徴です。のビューにラベルと画像を追加しましたUIAlertControllerが、それらには視差機能がありません。つまり、ユーザーが電話を動かしたときにかなり奇妙に見えます。

2 つのオプションを探していますが、どちらも実行する方法が見つかりません。
最初の解決策は、アプリのどこでもサポートされていないことを確認して、視差を無効にすることです。
2 番目の解決策は、視差サポートをラベルと画像に追加することです。
とにかく、ここにコードがあります:

UIAlertController *welcomeAlertController = [UIAlertController
                                              alertControllerWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Would you like to send %@ a message?", @"This message is displayed after adding a new message receiver. The %@ is the name of the receiver."), self.receiver.name]
                                              message:@"\n\n\n\n\n\n\n\n"
                                              preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction *cancelAction = [UIAlertAction
                               actionWithTitle:NSLocalizedString(@"Skip", @"Skip: meaning user can skip a certain step.")
                               style:UIAlertActionStyleCancel
                               handler:^(UIAlertAction *action)
                               {
                                   [self cancelButtonPressed];
                               }];

UIAlertAction *okAction = [UIAlertAction
                           actionWithTitle:NSLocalizedString(@"Send", @"Send: meaning user can send information to somewhere.")
                           style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction *action)
                           {
                               [self sendButtonClicked];
                           }];

[welcomeAlertController addAction:cancelAction];
[welcomeAlertController addAction:okAction];

smsView.frame = CGRectMake(20, 80, 240, 95);
messageBackgroundView.frame = CGRectMake(0, 0, 240, 80);

warningLabel.frame = CGRectMake(20, 170, 240, 40);
warningLabel.textColor = [UIColor blackColor];

[welcomeAlertController.view addSubview:smsView];  // An UIView
[welcomeAlertController.view addSubview:warningLabel];

[self presentViewController:welcomeAlertController animated:YES completion:nil];
4

1 に答える 1

6

ビューに視差を追加するのは非常に簡単です。それはこのように動作します:

UIInterpolatingMotionEffect *horizontalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
horizontalMotionEffect.minimumRelativeValue = @(-30);
horizontalMotionEffect.maximumRelativeValue = @(30);

UIInterpolatingMotionEffect *verticalMotionEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
verticalMotionEffect.minimumRelativeValue = @(-30);
verticalMotionEffect.maximumRelativeValue = @(30);

UIMotionEffectGroup *group = [UIMotionEffectGroup new];
group.motionEffects = @[horizontalMotionEffect, verticalMotionEffect];
[yourViewHere addMotionEffect:group];

@(30)をいじって、すべての外観を定義することもできます。

私に関する限り、視差をオフにすることはできずUIAlertController、 a をサブクラス化して独自の UI コピーを実装することをお勧めしますUIView

于 2014-10-23T10:48:52.523 に答える