@@ -215,6 +215,7 @@ - (id)initWithTitle:(NSString *)title andMessage:(NSString *)message
215215 if (self) {
216216 _title = title;
217217 _message = message;
218+ _enabledParallaxEffect = YES ;
218219 self.items = [[NSMutableArray alloc ] init ];
219220 }
220221 return self;
@@ -361,6 +362,9 @@ - (void)show
361362 self.didShowHandler (self);
362363 }
363364 [[NSNotificationCenter defaultCenter ] postNotificationName: SIAlertViewDidShowNotification object: self userInfo: nil ];
365+ #ifdef __IPHONE_7_0
366+ [self addParallaxEffect ];
367+ #endif
364368
365369 [SIAlertView setAnimating: NO ];
366370
@@ -385,6 +389,9 @@ - (void)dismissAnimated:(BOOL)animated cleanup:(BOOL)cleanup
385389 self.willDismissHandler (self);
386390 }
387391 [[NSNotificationCenter defaultCenter ] postNotificationName: SIAlertViewWillDismissNotification object: self userInfo: nil ];
392+ #ifdef __IPHONE_7_0
393+ [self removeParallaxEffect ];
394+ #endif
388395 }
389396
390397 void (^dismissComplete)(void ) = ^{
@@ -1035,4 +1042,34 @@ -(void)setColor:(UIColor *)color toButtonsOfType:(SIAlertViewButtonType)type {
10351042 }
10361043}
10371044
1045+ # pragma mark -
1046+ # pragma mark Enable parallax effect (iOS7 only)
1047+
1048+ #ifdef __IPHONE_7_0
1049+ - (void )addParallaxEffect
1050+ {
1051+ if (_enabledParallaxEffect && NSClassFromString (@" UIInterpolatingMotionEffect" ))
1052+ {
1053+ UIInterpolatingMotionEffect *effectHorizontal = [[UIInterpolatingMotionEffect alloc ] initWithKeyPath: @" position.x" type: UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
1054+ UIInterpolatingMotionEffect *effectVertical = [[UIInterpolatingMotionEffect alloc ] initWithKeyPath: @" position.y" type: UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
1055+ [effectHorizontal setMaximumRelativeValue: @(20 .0f )];
1056+ [effectHorizontal setMinimumRelativeValue: @(-20 .0f )];
1057+ [effectVertical setMaximumRelativeValue: @(50 .0f )];
1058+ [effectVertical setMinimumRelativeValue: @(-50 .0f )];
1059+ [self .containerView addMotionEffect: effectHorizontal];
1060+ [self .containerView addMotionEffect: effectVertical];
1061+ }
1062+ }
1063+
1064+ - (void )removeParallaxEffect
1065+ {
1066+ if (_enabledParallaxEffect && NSClassFromString (@" UIInterpolatingMotionEffect" ))
1067+ {
1068+ [self .containerView.motionEffects enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
1069+ [self .containerView removeMotionEffect: obj];
1070+ }];
1071+ }
1072+ }
1073+ #endif
1074+
10381075@end
0 commit comments