Disable iOS parallax in UIAlertController

The application I am developing only supports portrait mode. However, in iOS8, now deprecated UIAlertView

can go to terrain and display some other minor issues. To fix this, I decided to give it a try UIAlertController

. This works, but I have a new problem that is still a little annoying. The warning no longer goes into the terrain, but there is a parallax movement in it. I've added a shortcut and an image to the view UIAlertController

, but they don't have a parallax function, which means it looks rather strange when users move the phone.

I am looking for two options, but I cannot find how to accomplish them. The first solution would be to disable parallax, seeing as we don't support it anywhere in the app.
The second solution is to add parallax support to the label and image.
Anyway, here's a piece of code:

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];

      

+3


source to share


1 answer


Adding parallax to views is deadly simple. It works like this:

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];

      



You might want to play with the meanings @(30)

to determine how things look.

And as far as I know, you cannot turn parallax off on UIAlertController

, and you may want to implement your own copy of the UI by subclassing UIView

.

+6


source







All Articles