Skip to content

Instantly share code, notes, and snippets.

@mbigatti
Created October 17, 2013 08:17
Show Gist options
  • Save mbigatti/7021084 to your computer and use it in GitHub Desktop.
Save mbigatti/7021084 to your computer and use it in GitHub Desktop.
Add device tilting support to your UIView to get an effect similar to native UIAlertView
#import <UIKit/UIKit.h>
@interface UIView (BMXMotionEffect)
- (void)BMX_addTwoDimensionMotionEffectWithDepth:(CGFloat)depth;
@end
#import "UIView+BMXMotionEffect.h"
@implementation UIView (BMXMotionEffect)
- (void)BMX_addTwoDimensionMotionEffectWithDepth:(CGFloat)depth
{
UIInterpolatingMotionEffect *effectX = [[UIInterpolatingMotionEffect alloc] initWithKeyPath: @"center.x" type: UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
effectX.minimumRelativeValue = @(-depth);
effectX.maximumRelativeValue = @(depth);
UIInterpolatingMotionEffect *effectY = [[UIInterpolatingMotionEffect alloc] initWithKeyPath: @"center.y" type: UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
effectY.minimumRelativeValue = @(-depth);
effectY.maximumRelativeValue = @(depth);
[self addMotionEffect: effectX];
[self addMotionEffect: effectY];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment