Remove CPAnimation

This commit is contained in:
Yann Diorcet 2012-08-14 11:09:16 +02:00
parent 1090d8c5d4
commit 69a1bb7fea
6 changed files with 47 additions and 394 deletions

View file

@ -20,9 +20,6 @@
#import "UICallBar.h"
#import "LinphoneManager.h"
#import "PhoneMainView.h"
#import "CPAnimationSequence.h"
#import "CPAnimationStep.h"
#import "Utils.h"
#include "linphonecore.h"
@ -281,29 +278,55 @@
}
#pragma mark -
#pragma mark -
- (void)showAnimation:(NSString*)animationID target:(UIView*)target completion:(void (^)(BOOL finished))completion {
CGRect frame = [target frame];
int original_y = frame.origin.y;
frame.origin.y = [[self view] frame].size.height;
[target setFrame:frame];
[target setHidden:FALSE];
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseOut
animations:^{
CGRect frame = [target frame];
frame.origin.y = original_y;
[target setFrame:frame];
}
completion:^(BOOL finished){
CGRect frame = [target frame];
frame.origin.y = original_y;
[target setFrame:frame];
completion(finished);
}];
}
- (void)hideAnimation:(NSString*)animationID target:(UIView*)target completion:(void (^)(BOOL finished))completion {
CGRect frame = [target frame];
int original_y = frame.origin.y;
[UIView animateWithDuration:0.5
delay:0.0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
CGRect frame = [target frame];
frame.origin.y = [[self view] frame].size.height;
[target setFrame:frame];
}
completion:^(BOOL finished){
CGRect frame = [target frame];
frame.origin.y = original_y;
[target setHidden:TRUE];
[target setFrame:frame];
completion(finished);
}];
}
- (void)showPad:(BOOL)animated {
[dialerButton setOn];
if([padView isHidden]) {
if(animated) {
CGRect frame = [padView frame];
int original_y = frame.origin.y;
frame.origin.y = [[self view] frame].size.height;
[padView setFrame:frame];
[padView setHidden:FALSE];
CPAnimationSequence* move = [[CPAnimationSequence sequenceWithSteps:
[[CPAnimationStep after:0.0
for:0.5
options:UIViewAnimationOptionCurveEaseOut
animate:^{
CGRect frame = [padView frame];
frame.origin.y = original_y;
[padView setFrame:frame];
}] autorelease],
nil
] autorelease];
[move run];
[self showAnimation:@"show" target:padView completion:^(BOOL finished){}];
} else {
[padView setHidden:FALSE];
}
@ -314,28 +337,7 @@
[dialerButton setOff];
if(![padView isHidden]) {
if(animated) {
CGRect frame = [padView frame];
int original_y = frame.origin.y;
CPAnimationSequence* move = [[CPAnimationSequence sequenceWithSteps:
[[CPAnimationStep after:0.0
for:0.5
options:UIViewAnimationOptionCurveEaseIn
animate:^{
CGRect frame = [padView frame];
frame.origin.y = [[self view] frame].size.height;
[padView setFrame:frame];
}] autorelease],
[[CPAnimationStep after:0.0
animate:^{
CGRect frame = [padView frame];
frame.origin.y = original_y;
[padView setHidden:TRUE];
[padView setFrame:frame];
}] autorelease],
nil
] autorelease];
[move run];
[self hideAnimation:@"hide" target:padView completion:^(BOOL finished){}];
} else {
[padView setHidden:TRUE];
}
@ -346,23 +348,7 @@
[optionsButton setOn];
if([optionsView isHidden]) {
if(animated) {
CGRect frame = [optionsView frame];
int original_y = frame.origin.y;
frame.origin.y = [[self view] frame].size.height;
[optionsView setFrame:frame];
[optionsView setHidden:FALSE];
CPAnimationSequence* move = [[CPAnimationSequence sequenceWithSteps:
[[CPAnimationStep after:0.0
for:0.5
options:UIViewAnimationOptionCurveEaseOut
animate:^{
CGRect frame = [optionsView frame];
frame.origin.y = original_y;
[optionsView setFrame:frame];
}] autorelease],
nil
] autorelease];
[move run];
[self showAnimation:@"show" target:optionsView completion:^(BOOL finished){}];
} else {
[optionsView setHidden:FALSE];
}
@ -373,28 +359,7 @@
[optionsButton setOff];
if(![optionsView isHidden]) {
if(animated) {
CGRect frame = [optionsView frame];
int original_y = frame.origin.y;
CPAnimationSequence* move = [[CPAnimationSequence sequenceWithSteps:
[[CPAnimationStep after:0.0
for:0.5
options:UIViewAnimationOptionCurveEaseIn
animate:^{
CGRect frame = [optionsView frame];
frame.origin.y = [[self view] frame].size.height;
[optionsView setFrame:frame];
}] autorelease],
[[CPAnimationStep after:0.0
animate:^{
CGRect frame = [optionsView frame];
frame.origin.y = original_y;
[optionsView setHidden:TRUE];
[optionsView setFrame:frame];
}] autorelease],
nil
] autorelease];
[move run];
[self hideAnimation:@"hide" target:optionsView completion:^(BOOL finished){}];
} else {
[optionsView setHidden:TRUE];
}

View file

@ -1,26 +0,0 @@
// Created by Yang Meyer on 26.07.11.
// Copyright 2011-2012 compeople AG. All rights reserved.
#import <Foundation/Foundation.h>
#import "CPAnimationStep.h"
/**
A CPAnimationSequence defines a sequence of CPAnimationStep objects, which can
be `-run` animatedly or non-animatedly.
CPAnimationSequence implements the Composite design pattern, with CPAnimationStep
as the base class.
*/
@interface CPAnimationSequence : CPAnimationStep
#pragma mark - constructors
+ (id) sequenceWithSteps:(CPAnimationStep*)first, ... NS_REQUIRES_NIL_TERMINATION;
#pragma mark - properties
/** Animations steps, from first to last. */
@property (nonatomic, strong, readonly) NSArray* steps;
@end

View file

@ -1,84 +0,0 @@
// Created by Yang Meyer on 26.07.11.
// Copyright 2011-2012 compeople AG. All rights reserved.
#import "CPAnimationSequence.h"
@interface CPAnimationStep(hidden)
- (NSArray*) animationStepArray;
@end
@interface CPAnimationSequence()
@property (nonatomic, strong, readwrite) NSArray* steps;
@end
#pragma mark -
@implementation CPAnimationSequence
@synthesize steps;
#pragma mark - Object lifecycle
+ (id) sequenceWithSteps:(CPAnimationStep*)first, ... {
CPAnimationSequence* instance = [[self alloc] init];
if (instance) {
NSMutableArray* tempSteps = [[NSMutableArray alloc] initWithCapacity:10];
va_list args;
va_start(args, first);
[tempSteps insertObject:first atIndex:0];
CPAnimationStep* aStep;
while ((aStep = va_arg(args, CPAnimationStep*))) {
[tempSteps insertObject:aStep atIndex:0];
}
instance.steps = [NSArray arrayWithArray:tempSteps];
va_end(args);
[tempSteps release];
}
return instance;
}
- (void) dealloc {
[steps release];
[super dealloc];
}
#pragma mark - property override
- (void) setDelay:(NSTimeInterval)delay {
NSAssert(NO, @"Setting a delay on a sequence is undefined and therefore disallowed!");
}
- (void) setDuration:(NSTimeInterval)duration {
NSAssert(NO, @"Setting a duration on a sequence is undefined and therefore disallowed!");
}
- (void) setOptions:(UIViewAnimationOptions)options {
NSAssert(NO, @"Setting options on a sequence is undefined and therefore disallowed!");
}
#pragma mark - build the sequence
- (NSArray*) animationStepArray {
NSMutableArray* array = [NSMutableArray arrayWithCapacity:[self.steps count]];
for (CPAnimationStep* current in self.steps) {
[array addObjectsFromArray:[current animationStepArray]];
}
return array;
}
#pragma mark - pretty-print
- (NSString*) description {
NSMutableString* sequenceBody = [[NSMutableString alloc] initWithCapacity:100*[self.steps count]];
for (CPAnimationStep* step in self.steps) {
[sequenceBody appendString:[step description]];
}
// indent
[sequenceBody replaceOccurrencesOfString:@"\n"
withString:@"\n "
options:NSCaseInsensitiveSearch
range:NSMakeRange(0, [sequenceBody length])];
return [NSString stringWithFormat:@"\n(sequence:%@\n)", sequenceBody];
}
@end

View file

@ -1,46 +0,0 @@
// Created by Yang Meyer on 26.07.11.
// Copyright 2011 compeople AG. All rights reserved.
#import <Foundation/Foundation.h>
/** Helper type definition for the component. */
typedef void (^AnimationStep)(void);
/**
A CPAnimationStep defines a single animation object with a delay, duration, execution block and animation options.
*/
@interface CPAnimationStep : NSObject
#pragma mark - constructors
+ (id) after:(NSTimeInterval)delay
animate:(AnimationStep)step;
+ (id) for:(NSTimeInterval)duration
animate:(AnimationStep)step;
+ (id) after:(NSTimeInterval)delay
for:(NSTimeInterval)duration
animate:(AnimationStep)step;
+ (id) after:(NSTimeInterval)delay
for:(NSTimeInterval)duration
options:(UIViewAnimationOptions)theOptions
animate:(AnimationStep)step;
#pragma mark - properties (normally already set by the constructor)
@property (nonatomic) NSTimeInterval delay;
@property (nonatomic) NSTimeInterval duration;
@property (nonatomic, strong) AnimationStep step;
@property (nonatomic) UIViewAnimationOptions options;
#pragma mark - execution
/** Starts the step execution. */
- (void) runAnimated:(BOOL)animated;
/** Shortcut for [step runAnimated:YES] */
- (void) run;
@end

View file

@ -1,132 +0,0 @@
// Created by Yang Meyer on 26.07.11.
// Copyright 2011-2012 compeople AG. All rights reserved.
#import "CPAnimationStep.h"
@interface CPAnimationStep()
/** A temporary reverse queue of animation steps, i.e. from last to first.
It is created when the step is run, and is modified during the animation,
and is destroyed when the animation finishes. */
@property (nonatomic, strong) NSMutableArray* consumableSteps;
@end
@implementation CPAnimationStep
@synthesize delay, duration, step, options;
@synthesize consumableSteps;
#pragma mark overrides
#pragma mark construction
+ (id) after:(NSTimeInterval)delay animate:(AnimationStep)step {
return [self after:delay for:0.0 options:0 animate:step];
}
+ (id) for:(NSTimeInterval)duration animate:(AnimationStep)step {
return [self after:0.0 for:duration options:0 animate:step];
}
+ (id) after:(NSTimeInterval)delay for:(NSTimeInterval)duration animate:(AnimationStep)step {
return [self after:delay for:duration options:0 animate:step];
}
+ (id) after:(NSTimeInterval)theDelay
for:(NSTimeInterval)theDuration
options:(UIViewAnimationOptions)theOptions
animate:(AnimationStep)theStep {
CPAnimationStep* instance = [[self alloc] init];
if (instance) {
instance.delay = theDelay;
instance.duration = theDuration;
instance.options = theOptions;
instance.step = theStep;
}
return instance;
}
- (void)dealloc {
[step release];
[super dealloc];
}
#pragma mark action
// From http://stackoverflow.com/questions/4007023/blocks-instead-of-performselectorwithobjectafterdelay
+ (void) runBlock:(AnimationStep)block afterDelay:(NSTimeInterval)delay {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC*delay), dispatch_get_current_queue(), block);
}
- (NSArray*) animationStepArray {
// subclasses must override this!
return [NSArray arrayWithObject:self];
}
- (void) runAnimated:(BOOL)animated {
if (!self.consumableSteps) {
self.consumableSteps = [[NSMutableArray alloc] initWithArray:[self animationStepArray]];
}
if (![self.consumableSteps count]) { // recursion anchor
[self.consumableSteps release];
self.consumableSteps = nil;
return; // we're done
}
void (^completionStep)(BOOL) = ^(BOOL animated){
[self.consumableSteps removeLastObject];
[self runAnimated:animated]; // recurse!
};
CPAnimationStep* currentStep = [self.consumableSteps lastObject];
// Note: do not animate to short steps
if (animated && currentStep.duration >= 0.02) {
[UIView animateWithDuration:currentStep.duration
delay:currentStep.delay
options:currentStep.options
animations:currentStep.step
completion:^(BOOL finished) {
if (finished) {
completionStep(TRUE);
} else {
completionStep(FALSE);
}
}];
} else {
void (^execution)(void) = ^{
currentStep.step();
completionStep(FALSE);
};
if (animated && currentStep.delay) {
[CPAnimationStep runBlock:execution afterDelay:currentStep.delay];
} else {
execution();
}
}
}
- (void) run {
[self runAnimated:YES];
}
#pragma mark - pretty-print
- (NSString*) description {
NSMutableString* result = [[NSMutableString alloc] initWithCapacity:100];
[result appendString:@"\n["];
if (self.delay > 0.0) {
[result appendFormat:@"after:%.1f ", self.delay];
}
if (self.duration > 0.0) {
[result appendFormat:@"for:%.1f ", self.duration];
}
if (self.options > 0) {
[result appendFormat:@"options:%d ", self.options];
}
[result appendFormat:@"animate:%@", self.step];
[result appendString:@"]"];
return result;
}
@end

View file

@ -743,10 +743,6 @@
D3832801158100E400FA0D23 /* history_over.png in Resources */ = {isa = PBXBuildFile; fileRef = D38327FD158100E400FA0D23 /* history_over.png */; };
D3832802158100E400FA0D23 /* settings_over.png in Resources */ = {isa = PBXBuildFile; fileRef = D38327FE158100E400FA0D23 /* settings_over.png */; };
D3832803158100E400FA0D23 /* chat_over.png in Resources */ = {isa = PBXBuildFile; fileRef = D38327FF158100E400FA0D23 /* chat_over.png */; };
D389362615A6D19800A3A3AA /* CPAnimationSequence.m in Sources */ = {isa = PBXBuildFile; fileRef = D389362315A6D19800A3A3AA /* CPAnimationSequence.m */; };
D389362715A6D19800A3A3AA /* CPAnimationSequence.m in Sources */ = {isa = PBXBuildFile; fileRef = D389362315A6D19800A3A3AA /* CPAnimationSequence.m */; };
D389362815A6D19800A3A3AA /* CPAnimationStep.m in Sources */ = {isa = PBXBuildFile; fileRef = D389362515A6D19800A3A3AA /* CPAnimationStep.m */; };
D389362915A6D19800A3A3AA /* CPAnimationStep.m in Sources */ = {isa = PBXBuildFile; fileRef = D389362515A6D19800A3A3AA /* CPAnimationStep.m */; };
D389363915A6D53200A3A3AA /* chat_bubble_incoming.9.png in Resources */ = {isa = PBXBuildFile; fileRef = D389363715A6D53200A3A3AA /* chat_bubble_incoming.9.png */; };
D389363B15A6D53200A3A3AA /* chat_bubble_outgoing.9.png in Resources */ = {isa = PBXBuildFile; fileRef = D389363815A6D53200A3A3AA /* chat_bubble_outgoing.9.png */; };
D38D14AF15A30B3D008497E8 /* cell_call_first_highlight.png in Resources */ = {isa = PBXBuildFile; fileRef = D38D14AD15A30B3D008497E8 /* cell_call_first_highlight.png */; };
@ -1744,10 +1740,6 @@
D38327FD158100E400FA0D23 /* history_over.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = history_over.png; path = Resources/history_over.png; sourceTree = "<group>"; };
D38327FE158100E400FA0D23 /* settings_over.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = settings_over.png; path = Resources/settings_over.png; sourceTree = "<group>"; };
D38327FF158100E400FA0D23 /* chat_over.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = chat_over.png; path = Resources/chat_over.png; sourceTree = "<group>"; };
D389362215A6D19800A3A3AA /* CPAnimationSequence.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CPAnimationSequence.h; path = Utils/CPAnimation/CPAnimationSequence.h; sourceTree = "<group>"; };
D389362315A6D19800A3A3AA /* CPAnimationSequence.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CPAnimationSequence.m; path = Utils/CPAnimation/CPAnimationSequence.m; sourceTree = "<group>"; };
D389362415A6D19800A3A3AA /* CPAnimationStep.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CPAnimationStep.h; path = Utils/CPAnimation/CPAnimationStep.h; sourceTree = "<group>"; };
D389362515A6D19800A3A3AA /* CPAnimationStep.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CPAnimationStep.m; path = Utils/CPAnimation/CPAnimationStep.m; sourceTree = "<group>"; };
D389363715A6D53200A3A3AA /* chat_bubble_incoming.9.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = chat_bubble_incoming.9.png; path = Resources/chat_bubble_incoming.9.png; sourceTree = "<group>"; };
D389363815A6D53200A3A3AA /* chat_bubble_outgoing.9.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = chat_bubble_outgoing.9.png; path = Resources/chat_bubble_outgoing.9.png; sourceTree = "<group>"; };
D38D14AD15A30B3D008497E8 /* cell_call_first_highlight.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = cell_call_first_highlight.png; path = Resources/cell_call_first_highlight.png; sourceTree = "<group>"; };
@ -3074,7 +3066,6 @@
children = (
D380801215C299D0005BE9BC /* ColorSpaceUtilites.m */,
D380801115C29984005BE9BC /* ColorSpaceUtilities.h */,
D38935F715A6D06800A3A3AA /* CPAnimation */,
D3807FB615C28940005BE9BC /* DCRoundSwitch */,
D32B9DFA15A2F131000B6DEC /* FastAddressBook.h */,
D32B9DFB15A2F131000B6DEC /* FastAddressBook.m */,
@ -3185,17 +3176,6 @@
path = Views;
sourceTree = "<group>";
};
D38935F715A6D06800A3A3AA /* CPAnimation */ = {
isa = PBXGroup;
children = (
D389362215A6D19800A3A3AA /* CPAnimationSequence.h */,
D389362315A6D19800A3A3AA /* CPAnimationSequence.m */,
D389362415A6D19800A3A3AA /* CPAnimationStep.h */,
D389362515A6D19800A3A3AA /* CPAnimationStep.m */,
);
name = CPAnimation;
sourceTree = "<group>";
};
D398D3031594B0FB00FD553C /* Settings */ = {
isa = PBXGroup;
children = (
@ -4302,8 +4282,6 @@
D32B6E2915A5BC440033019F /* ChatRoomTableViewController.m in Sources */,
D32B6E3815A5C2430033019F /* ChatModel.m in Sources */,
D3A8BB7015A6C7D500F96BE5 /* UIChatRoomCell.m in Sources */,
D389362615A6D19800A3A3AA /* CPAnimationSequence.m in Sources */,
D389362815A6D19800A3A3AA /* CPAnimationStep.m in Sources */,
D3128FE115AABC7E00A2147A /* ContactDetailsViewController.m in Sources */,
D37C639515AADDAF009D0BAC /* UIContactDetailsHeader.m in Sources */,
D37C639B15AADEF6009D0BAC /* ContactDetailsTableViewController.m in Sources */,
@ -4393,8 +4371,6 @@
D32B6E2A15A5BC440033019F /* ChatRoomTableViewController.m in Sources */,
D32B6E3915A5C2430033019F /* ChatModel.m in Sources */,
D3A8BB7115A6C7D500F96BE5 /* UIChatRoomCell.m in Sources */,
D389362715A6D19800A3A3AA /* CPAnimationSequence.m in Sources */,
D389362915A6D19800A3A3AA /* CPAnimationStep.m in Sources */,
D3128FE215AABC7E00A2147A /* ContactDetailsViewController.m in Sources */,
D37C639615AADDAF009D0BAC /* UIContactDetailsHeader.m in Sources */,
D37C639C15AADEF6009D0BAC /* ContactDetailsTableViewController.m in Sources */,