-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUIImageView+MotionEffect.m
37 lines (30 loc) · 1.15 KB
/
UIImageView+MotionEffect.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// UIImageView+Parallax.m
// Oscar Dominguez
//
// Created by Oscar Domínguez on 31/03/14.
// Copyright (c) 2014 Oscar Dominguez. All rights reserved.
//
#import "UIImageView+MotionEffect.h"
@implementation UIImageView (Parallax)
-(void)addMotionEffect{
UIInterpolatingMotionEffect *verticalMotionEffect =
[[UIInterpolatingMotionEffect alloc]
initWithKeyPath:@"center.y"
type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis];
verticalMotionEffect.minimumRelativeValue = @(-10);
verticalMotionEffect.maximumRelativeValue = @(10);
UIInterpolatingMotionEffect *horizontalMotionEffect =
[[UIInterpolatingMotionEffect alloc]
initWithKeyPath:@"center.x"
type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
horizontalMotionEffect.minimumRelativeValue = @(-10);
horizontalMotionEffect.maximumRelativeValue = @(10);
UIMotionEffectGroup *group = [UIMotionEffectGroup new];
group.motionEffects = @[horizontalMotionEffect, verticalMotionEffect];
[self addMotionEffect:group];
}
-(void)removeMotionEffect{
[self removeMotionEffect:[self.motionEffects objectAtIndex:0]];
}
@end