Created
February 13, 2014 06:30
-
-
Save keicoder/8970785 to your computer and use it in GitHub Desktop.
objective-c : make basic table view with custom background and jason data v.7
This file contains hidden or 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
| //make basic table view with custom background and jason data v.7 | |
| //add motion effects | |
| - (void)viewDidLoad | |
| { | |
| if (debug==1) {NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));} | |
| ... | |
| // Background image | |
| // UIImageView* backgroundImageView = [[UIImageView alloc] initWithImage: | |
| // [UIImage imageNamed:@"Background-LowerLayer.png"]]; | |
| // [self.view addSubview:backgroundImageView]; | |
| // | |
| // // Header logo | |
| // UIImageView* header = [[UIImageView alloc] initWithImage: | |
| // [UIImage imageNamed:@"Sarnie.png"]]; | |
| // header.center = CGPointMake(220, 190); | |
| // [self.view addSubview:header]; | |
| //add motion effects | |
| // 1. add the lower background layer | |
| UIImageView* backgroundImageView = [[UIImageView alloc] | |
| initWithImage:[UIImage imageNamed:@"Background-LowerLayer.png"]]; | |
| backgroundImageView.frame = CGRectInset(self.view.frame, -50.0f, -50.0f); | |
| [self.view addSubview:backgroundImageView]; | |
| [self addMotionEffectToView: backgroundImageView magnitude:50.0f]; | |
| // 2. add the background mid layer | |
| UIImageView* midLayerImageView = [[UIImageView alloc] | |
| initWithImage:[UIImage imageNamed:@"Background-MidLayer.png"]]; | |
| [self.view addSubview:midLayerImageView]; | |
| // 3. add the foreground image | |
| UIImageView* header = [[UIImageView alloc] | |
| initWithImage:[UIImage imageNamed:@"Sarnie.png"]]; | |
| header.center = CGPointMake(220, 190); | |
| [self.view addSubview:header]; | |
| [self addMotionEffectToView:header magnitude:-20.0f]; | |
| ... | |
| } | |
| #pragma mark - //add motion effects | |
| - (void)addMotionEffectToView:(UIView*)view magnitude:(CGFloat)magnitude { | |
| if (debug==1) {NSLog(@"Running %@ '%@'", self.class, NSStringFromSelector(_cmd));} | |
| //add motion effects | |
| //UIInterpolatingMotionEffect instances: tracks horizontal motion and vertical motion. | |
| UIInterpolatingMotionEffect* xMotion = [[UIInterpolatingMotionEffect alloc] | |
| initWithKeyPath:@"center.x" | |
| type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; | |
| xMotion.minimumRelativeValue = @(-magnitude); | |
| xMotion.maximumRelativeValue = @(magnitude); | |
| UIInterpolatingMotionEffect* yMotion = [[UIInterpolatingMotionEffect alloc] | |
| initWithKeyPath:@"center.y" | |
| type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; | |
| yMotion.minimumRelativeValue = @(-magnitude); | |
| yMotion.maximumRelativeValue = @(magnitude); | |
| UIMotionEffectGroup* group = [[UIMotionEffectGroup alloc] init]; | |
| group.motionEffects = @[xMotion, yMotion]; | |
| [view addMotionEffect:group]; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment