在UIAlertController中禁用视差iOS

use*_*317 3 ios parallax ios8 uialertcontroller

我正在开发的应用程序仅支持纵向模式.但是,在iOS8中,现在已弃用的UIAlertView可以进入横向并显示其他一些小问题.为了解决这个问题,我决定UIAlertController尝试一下.它有效,但我有一个新问题仍然有点烦人.警报不再进入景观,但确实以视差运动为特色.我在UIAlertController视图中添加了一个标签和一个图像,但那些不具有视差的东西,这意味着当用户移动手机时它看起来很奇怪.

我正在寻找两种选择,但我找不到如何做其中任何一种.
第一个解决方案是禁用视差,看看我们如何在应用程序的任何地方不支持它.
第二种解决方案是将视差支持添加到标签和图像.
无论如何,这是一段代码:

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];
Run Code Online (Sandbox Code Playgroud)

Ser*_*yov 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];
Run Code Online (Sandbox Code Playgroud)

您可能希望使用值@(30)来定义它的外观.

就我而言,你无法关闭视差UIAlertController,你可能希望通过继承a来实现自己的UI副本UIView.