Skip to content

Instantly share code, notes, and snippets.

@bwalkin bwalkin/ViewController.m Secret
Last active Aug 6, 2016

Embed
What would you like to do?
iOS Code Exported from Origami
#import "ViewController.h"
#import <POP/POP.h>
#import <POP/POPLayerExtras.h>
@interface ViewController ()
@property (nonatomic) CGFloat photoZoomProgress;
@property (nonatomic) CGFloat fadeProgress;
@end
@implementation ViewController
// photoZoom transition
- (void)togglePhotoZoom:(BOOL)on {
POPSpringAnimation *animation = [self pop_animationForKey:@"photoZoom"];
if (!animation) {
animation = [POPSpringAnimation animation];
animation.springBounciness = 7;
animation.springSpeed = 2;
animation.property = [POPAnimatableProperty propertyWithName:@"photoZoomProgress" initializer:^(POPMutableAnimatableProperty *prop) {
prop.readBlock = ^(ViewController *obj, CGFloat values[]) {
values[0] = obj.photoZoomProgress;
};
prop.writeBlock = ^(ViewController *obj, const CGFloat values[]) {
obj.photoZoomProgress = values[0];
};
prop.threshold = 0.001;
}];
[self pop_addAnimation:animation forKey:@"photoZoom"];
}
animation.toValue = on ? @(1.0) : @(0.0);
}
- (void)setPhotoZoomProgress:(CGFloat)progress {
_photoZoomProgress = progress;
CGFloat alpha = POPTransition(progress, 1, 0);
self.story.layer.opacity = alpha;
CGFloat scale = POPTransition(progress, 0.4797, 0.55);
POPLayerSetScaleXY(self.photo.layer, scale);
CGFloat yPosition = POPTransition(progress, -186, 0);
POPLayerSetTranslationY(self.photo.layer, POPPixelsToPoints(-yPosition));
CGFloat scale2 = POPTransition(progress, 1, 0.97);
POPLayerSetScaleXY(self.story.layer, scale2);
CGFloat rotation = POPTransition(progress, 0, 30);
POPLayerSetRotationZ(self.photo.layer, POPDegreesToRadians(rotation));
}
// fade transition
- (void)toggleFade:(BOOL)on {
POPSpringAnimation *animation = [self pop_animationForKey:@"fade"];
if (!animation) {
animation = [POPSpringAnimation animation];
animation.springBounciness = 15;
animation.springSpeed = 2;
animation.property = [POPAnimatableProperty propertyWithName:@"fadeProgress" initializer:^(POPMutableAnimatableProperty *prop) {
prop.readBlock = ^(ViewController *obj, CGFloat values[]) {
values[0] = obj.fadeProgress;
};
prop.writeBlock = ^(ViewController *obj, const CGFloat values[]) {
obj.fadeProgress = values[0];
};
prop.threshold = 0.001;
}];
[self pop_addAnimation:animation forKey:@"fade"];
}
animation.toValue = on ? @(1.0) : @(0.0);
}
- (void)setFadeProgress:(CGFloat)progress {
_fadeProgress = progress;
CGFloat alpha2 = POPTransition(progress, 1, 0.3);
self.photo.layer.opacity = alpha2;
}
// Utilities
static inline CGFloat POPTransition(CGFloat progress, CGFloat startValue, CGFloat endValue) {
return startValue + (progress * (endValue - startValue));
}
static inline CGFloat POPDegreesToRadians(CGFloat degrees) {
return M_PI * (degrees / 180.0);
}
static inline CGFloat POPPixelsToPoints(CGFloat pixels) {
static CGFloat scale = -1;
if (scale < 0) {
scale = [UIScreen mainScreen].scale;
}
return pixels / scale;
}
@MoamenMohammed

This comment has been minimized.

Copy link

commented Mar 1, 2016

How i can make animation work on my project after integrating this code in my project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.