2323#define BUTTON_HEIGHT 50
2424#define CONTAINER_WIDTH 270
2525
26- const UIWindowLevel UIWindowLevelSIAlert = 1999 .0 ; // don't overlap system's alert
27- const UIWindowLevel UIWindowLevelSIAlertBackground = 1998 .0 ; // below the alert window
26+ const UIWindowLevel UIWindowLevelSIAlert = 1996 .0 ; // don't overlap system's alert
27+ const UIWindowLevel UIWindowLevelSIAlertBackground = 1985 .0 ; // below the alert window
2828
2929@class SIAlertBackgroundWindow;
3030
@@ -278,9 +278,14 @@ + (void)setAnimating:(BOOL)animating
278278+ (void )showBackground
279279{
280280 if (!__si_alert_background_window) {
281- CGFloat width = [UIScreen mainScreen ].bounds .size .width ;
282- CGFloat height = [UIScreen mainScreen ].bounds .size .height ;
283- __si_alert_background_window = [[SIAlertBackgroundWindow alloc ] initWithFrame: CGRectMake (0 , 0 , MIN (width, height), MAX (width, height))
281+ CGRect frame = [[UIScreen mainScreen ] bounds ];
282+ if ([[UIScreen mainScreen ] respondsToSelector: @selector (fixedCoordinateSpace )])
283+ {
284+ frame = [[[UIScreen mainScreen ] fixedCoordinateSpace ] convertRect: frame fromCoordinateSpace: [[UIScreen mainScreen ] coordinateSpace ]];
285+ }
286+
287+ __si_alert_background_window = [[SIAlertBackgroundWindow alloc ] initWithFrame: frame
288+
284289 andStyle: [SIAlertView currentAlertView ].backgroundStyle];
285290 [__si_alert_background_window makeKeyAndVisible ];
286291 __si_alert_background_window.alpha = 0 ;
@@ -512,6 +517,9 @@ - (void)show
512517 self.didShowHandler (self);
513518 }
514519 [[NSNotificationCenter defaultCenter ] postNotificationName: SIAlertViewDidShowNotification object: self userInfo: nil ];
520+ #ifdef __IPHONE_7_0
521+ [self addParallaxEffect ];
522+ #endif
515523
516524 [SIAlertView setAnimating: NO ];
517525
@@ -536,6 +544,9 @@ - (void)dismissAnimated:(BOOL)animated cleanup:(BOOL)cleanup
536544 self.willDismissHandler (self);
537545 }
538546 [[NSNotificationCenter defaultCenter ] postNotificationName: SIAlertViewWillDismissNotification object: self userInfo: nil ];
547+ #ifdef __IPHONE_7_0
548+ [self removeParallaxEffect ];
549+ #endif
539550 }
540551
541552 void (^dismissComplete)(void ) = ^{
@@ -877,6 +888,7 @@ - (CGFloat)heightForTitleLabel
877888 context: nil ];
878889 return ceil (rect.size .height );
879890 }
891+
880892 return 0 ;
881893}
882894
@@ -1225,4 +1237,34 @@ - (NSDictionary *)destructiveButtonAttributes
12251237 return attributes;
12261238}
12271239
1240+ # pragma mark -
1241+ # pragma mark Enable parallax effect (iOS7 only)
1242+
1243+ #ifdef __IPHONE_7_0
1244+ - (void )addParallaxEffect
1245+ {
1246+ if (_enabledParallaxEffect && NSClassFromString (@" UIInterpolatingMotionEffect" ))
1247+ {
1248+ UIInterpolatingMotionEffect *effectHorizontal = [[UIInterpolatingMotionEffect alloc ] initWithKeyPath: @" position.x" type: UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
1249+ UIInterpolatingMotionEffect *effectVertical = [[UIInterpolatingMotionEffect alloc ] initWithKeyPath: @" position.y" type: UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
1250+ [effectHorizontal setMaximumRelativeValue: @(20 .0f )];
1251+ [effectHorizontal setMinimumRelativeValue: @(-20 .0f )];
1252+ [effectVertical setMaximumRelativeValue: @(50 .0f )];
1253+ [effectVertical setMinimumRelativeValue: @(-50 .0f )];
1254+ [self .containerView addMotionEffect: effectHorizontal];
1255+ [self .containerView addMotionEffect: effectVertical];
1256+ }
1257+ }
1258+
1259+ - (void )removeParallaxEffect
1260+ {
1261+ if (_enabledParallaxEffect && NSClassFromString (@" UIInterpolatingMotionEffect" ))
1262+ {
1263+ [self .containerView.motionEffects enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL *stop) {
1264+ [self .containerView removeMotionEffect: obj];
1265+ }];
1266+ }
1267+ }
1268+ #endif
1269+
12281270@end
0 commit comments