@@ -260,6 +260,7 @@ - (id)initWithTitle:(NSString *)title andMessage:(NSString *)message
260260 if (self) {
261261 _title = title;
262262 _message = message;
263+ _enabledParallaxEffect = YES ;
263264 self.items = [[NSMutableArray alloc ] init ];
264265 }
265266 return self;
@@ -412,6 +413,9 @@ - (void)show
412413 self.didShowHandler (self);
413414 }
414415 [[NSNotificationCenter defaultCenter ] postNotificationName: SIAlertViewDidShowNotification object: self userInfo: nil ];
416+ #ifdef __IPHONE_7_0
417+ [self addParallaxEffect ];
418+ #endif
415419
416420 [SIAlertView setAnimating: NO ];
417421
@@ -436,6 +440,9 @@ - (void)dismissAnimated:(BOOL)animated cleanup:(BOOL)cleanup
436440 self.willDismissHandler (self);
437441 }
438442 [[NSNotificationCenter defaultCenter ] postNotificationName: SIAlertViewWillDismissNotification object: self userInfo: nil ];
443+ #ifdef __IPHONE_7_0
444+ [self removeParallaxEffect ];
445+ #endif
439446 }
440447
441448 void (^dismissComplete)(void ) = ^{
@@ -1128,4 +1135,34 @@ -(void)setColor:(UIColor *)color toButtonsOfType:(SIAlertViewButtonType)type {
11281135 }
11291136}
11301137
1138+ # pragma mark -
1139+ # pragma mark Enable parallax effect (iOS7 only)
1140+
1141+ #ifdef __IPHONE_7_0
1142+ - (void )addParallaxEffect
1143+ {
1144+ if (_enabledParallaxEffect && NSClassFromString (@" UIInterpolatingMotionEffect" ))
1145+ {
1146+ UIInterpolatingMotionEffect *effectHorizontal = [[UIInterpolatingMotionEffect alloc ] initWithKeyPath: @" position.x" type: UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
1147+ UIInterpolatingMotionEffect *effectVertical = [[UIInterpolatingMotionEffect alloc ] initWithKeyPath: @" position.y" type: UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
1148+ [effectHorizontal setMaximumRelativeValue: @(20 .0f )];
1149+ [effectHorizontal setMinimumRelativeValue: @(-20 .0f )];
1150+ [effectVertical setMaximumRelativeValue: @(50 .0f )];
1151+ [effectVertical setMinimumRelativeValue: @(-50 .0f )];
1152+ [self .containerView addMotionEffect: effectHorizontal];
1153+ [self .containerView addMotionEffect: effectVertical];
1154+ }
1155+ }
1156+
1157+ - (void )removeParallaxEffect
1158+ {
1159+ if (_enabledParallaxEffect && NSClassFromString (@" UIInterpolatingMotionEffect" ))
1160+ {
1161+ [self .containerView.motionEffects enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
1162+ [self .containerView removeMotionEffect: obj];
1163+ }];
1164+ }
1165+ }
1166+ #endif
1167+
11311168@end
0 commit comments