Skip to content

Commit 99a73ec

Browse files
committed
Merge pull request Sumi-Interactive#32 from Fr4ncis/master
Added parallax effect (iOS7)
2 parents 5d7d103 + d626e30 commit 99a73ec

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

SIAlertView/SIAlertView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ typedef void(^SIAlertViewHandler)(SIAlertView *alertView);
5656

5757
@property (nonatomic, readonly, getter = isVisible) BOOL visible;
5858

59+
@property (nonatomic, readonly, getter = isParallaxEffectEnabled) BOOL enabledParallaxEffect;
60+
5961
@property (nonatomic, strong) UIColor *viewBackgroundColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
6062
@property (nonatomic, strong) UIColor *titleColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;
6163
@property (nonatomic, strong) UIColor *messageColor NS_AVAILABLE_IOS(5_0) UI_APPEARANCE_SELECTOR;

SIAlertView/SIAlertView.m

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)