【问题标题】:Disable parallax iOS in UIAlertController在 UIAlertController 中禁用视差 iOS
【发布时间】:2014-10-21 10:36:40
【问题描述】:

我正在开发的应用只支持纵向模式。但是,在 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];

【问题讨论】:

  • Reddit post,过了几天没有回复,所以让他在这里发帖。
  • 我计划在宽限期内将赏金奖励给当前接受的答案,除非有人知道如何关闭视差。

标签: ios ios8 parallax uialertcontroller


【解决方案1】:

为视图添加视差非常简单。它的工作原理是这样的:

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 上的视差,您可能希望通过子类化 UIView 来实现您自己的 UI 副本。

【讨论】:

  • 我还不能投票给你的答案,但感谢你回答我的问题。这将需要一些调整以匹配 UIAlertController 但至少我可以继续。 +1(如果可以的话)
  • 与 uialertcontroller 的“本机”运动相比,该效果确实有些卡顿,但它确实有效。再次感谢
  • @user1945317 很高兴我能提供帮助。效果实际上是UIAlertController 的工作原理,只是因为我必须实现一次完全相同的UIAlertView 副本并在真实设备上进行比较。好吧,至少它是我们能得到的最接近的。
  • 将在宽限期内将赏金奖励给此,除非其他人出现以禁用视差的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
相关资源
最近更新 更多