Created
August 24, 2013 04:38
-
-
Save darcyliu/6326095 to your computer and use it in GitHub Desktop.
UIMotionEffect Demo
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
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
CGRect frame = self.view.bounds; | |
for (NSInteger i=0; i<10; i++) { | |
CGFloat left = (frame.size.width-100)/2+i%2*10; | |
CGFloat top = (frame.size.height-100)/2+i%3*10; | |
UIView *demoView = [[UIView alloc] initWithFrame:CGRectMake(left, top , 100, 100)]; | |
demoView.backgroundColor = [UIColor colorWithRed:i/12.0f green:i/18.0f blue:i/24.0f alpha:0.8]; | |
[self.view addSubview:demoView]; | |
UIInterpolatingMotionEffect *xAxis = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; | |
UIInterpolatingMotionEffect *yAxis = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; | |
left += i*50; | |
top += i *50; | |
xAxis.minimumRelativeValue = @(-left); | |
xAxis.maximumRelativeValue = @(left); | |
yAxis.minimumRelativeValue = @(-top); | |
yAxis.maximumRelativeValue = @(top); | |
UIMotionEffectGroup *motionEffectGroup = [[UIMotionEffectGroup alloc] init]; | |
motionEffectGroup.motionEffects = @[xAxis, yAxis]; | |
[demoView addMotionEffect:motionEffectGroup]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment