Last active
December 22, 2015 22:39
-
-
Save iGriever/6541396 to your computer and use it in GitHub Desktop.
UIMotionEffect setup on multiple views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Setup horizontal motion effect | |
UIInterpolatingMotionEffect *horizontalInterpolation = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; | |
horizontalInterpolation.minimumRelativeValue = @-kMotionViewControllerInterpolationValue; | |
horizontalInterpolation.maximumRelativeValue = @kMotionViewControllerInterpolationValue; | |
// Setup vertical motion effect | |
UIInterpolatingMotionEffect *verticalInterpolation = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; | |
verticalInterpolation.minimumRelativeValue = @-kMotionViewControllerInterpolationValue; | |
verticalInterpolation.maximumRelativeValue = @kMotionViewControllerInterpolationValue; | |
// Add squares view | |
for (NSInteger i=0; i<6; i++) | |
{ | |
NSInteger row = i/3; | |
NSInteger column = i%3; | |
UIView *squareView = [[UIView alloc] initWithFrame:CGRectMake(20 + column*100, 100 + row*100, 80, 80)]; | |
[squareView setBackgroundColor:[UIColor colorWithRed:row*100.0f/255.0f green:column*50.0f/255.0f blue:0.5f alpha:1.0f]]; | |
[squareView addMotionEffect:horizontalInterpolation]; | |
[squareView addMotionEffect:verticalInterpolation]; | |
[self.view addSubview:squareView]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment