Demo function: a demo of ios dollar falling effect.
Demo Description: The dollar falling effect demo. You can use multiple touch points. The more touch points, the larger the falling dollar denomination. The main code is MainView. m.
Demo screenshot:
Demo code description:
[Csharp]
-(Void) onTimer
{
UIImageView * dollarView;
UIImage * dollarImage;
// For effect... make it harder to get some of the other bill index's
// If it does not pass criteria reset back to 1
// Double tap upside down for 5 Dollar bill
If (billIndex> 2 ){
If (deviceTilt. y> 0.5f)
BillIndex = 5;
Else
BillIndex = 1;
}
Else if (billIndex> 1 ){
If (deviceTilt. x> 0.5f)
BillIndex = 3;
Else if (deviceTilt. x <-0.5f)
BillIndex = 4;
Else
BillIndex = 2;
}
Switch (billIndex ){
Case 2:
DollarImage = [UIImage imageNamed: @ "dol2.png"];
Break;
Case 3:
DollarImage = [UIImage imageNamed: @ "5dol.jpg"];
Break;
Case 4:
DollarImage = [UIImage imageNamed: @ "10dol.jpg"];
Break;
Case 5:
DollarImage = [UIImage imageNamed: @ "20dol.jpg"];
Break;
Default:
DollarImage = [UIImage imageNamed: @ "dollar.png"];
Break;
}
// The above is the check contact and different USD images are allocated
// For effect only draw one 2 dollar bill by resetting billIndex
If (billIndex = 2)
BillIndex = 1;
// The following is the core code of the animation part.
DollarView = [[UIImageView alloc] initWithImage: dollarImage];
Int scale = RANDOM_INT (1, 5 );
Int width = 100 * scale;
Int height = 44 * scale;
If (useEmitterRect ){
DollarView. frame = emitterRect;
//} Else if (deviceTilt. x> 0.5f | deviceTilt. y> 0.5f | deviceTilt. x <-0.5f | deviceTilt. y <-0.5f ){
} Else if (deviceTilt. y> 0.5f ){
DollarView. frame = CGRectMake (160-(width/2), 490, width, height );
} Else if (deviceTilt. y <-0.5f ){
DollarView. frame = CGRectMake (160-(width/2),-(height + 10), width, height );
} Else if (deviceTilt. x> 0.5f ){
DollarView. frame = CGRectMake (-(width + 10), 240-(height/2), width, height );
} Else if (deviceTilt. x <-0.5f ){
DollarView. frame = CGRectMake (330,240-(height/2), width, height );
} Else {
Switch (RANDOM_INT (0, 3 )){
Case 0:
DollarView. frame = CGRectMake (-300,-300,100 * scale, 44 * scale );
Break;
Case 1:
DollarView. frame = CGRectMake (470,-150,100 * scale, 44 * scale );
Break;
Case 3:
DollarView. frame = CGRectMake (470,630,100 * scale, 44 * scale );
Break;
Default:
DollarView. frame = CGRectMake (-150,630,100 * scale, 44 * scale );
Break;
}
}
[Self addSubview: dollarView];
If (helpView)
[Self bringSubviewToFront: helpView];
[UIView beginAnimations: nil context: dollarView];
[UIView setAnimationDuration: 2];
DollarView. frame = CGRectMake (RANDOM_INT (-50,370), RANDOM_INT (-25,665), 100, 44 );
Int radians = RANDOM_INT (0,360) * 0.0174532925;
[DollarView setTransform: CGAffineTransformMakeRotation (radians)];
[UIView setAnimationDelegate: self];
[UIView commitAnimations];
BillCount ++;
[BillList addObject: dollarView];
If ([billList count]> = MAX_BILLS ){
UIImageView * oldBill = (UIImageView *) [billList objectAtIndex: 0];
[BillList removeObjectAtIndex: 0];
[UIView beginAnimations: nil context: oldBill];
[UIView setAnimationDuration: 2];
[OldBill setAlpha: 0.0];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: @ selector (goPutThemBack: finished: context :)];
[UIView commitAnimations];
}
}
-(Void) onTimer
{
UIImageView * dollarView;
UIImage * dollarImage;
// For effect... make it harder to get some of the other bill index's
// If it does not pass criteria reset back to 1
// Double tap upside down for 5 Dollar bill
If (billIndex> 2 ){
If (deviceTilt. y> 0.5f)
BillIndex = 5;
Else
BillIndex = 1;
}
Else if (billIndex> 1 ){
If (deviceTilt. x> 0.5f)
BillIndex = 3;
Else if (deviceTilt. x <-0.5f)
BillIndex = 4;
Else
BillIndex = 2;
}
Switch (billIndex ){
Case 2:
DollarImage = [UIImage imageNamed: @ "dol2.png"];
Break;
Case 3:
DollarImage = [UIImage imageNamed: @ "5dol.jpg"];
Break;
Case 4:
DollarImage = [UIImage imageNamed: @ "10dol.jpg"];
Break;
Case 5:
DollarImage = [UIImage imageNamed: @ "20dol.jpg"];
Break;
Default:
DollarImage = [UIImage imageNamed: @ "dollar.png"];
Break;
}
// The above is the check contact and different USD images are allocated
// For effect only draw one 2 dollar bill by resetting billIndex
If (billIndex = 2)
BillIndex = 1;
// The following is the core code of the animation part.
DollarView = [[UIImageView alloc] initWithImage: dollarImage];
Int scale = RANDOM_INT (1, 5 );
Int width = 100 * scale;
Int height = 44 * scale;
If (useEmitterRect ){
DollarView. frame = emitterRect;
//} Else if (deviceTilt. x> 0.5f | deviceTilt. y> 0.5f | deviceTilt. x <-0.5f | deviceTilt. y <-0.5f ){
} Else if (deviceTilt. y> 0.5f ){
DollarView. frame = CGRectMake (160-(width/2), 490, width, height );
} Else if (deviceTilt. y <-0.5f ){
DollarView. frame = CGRectMake (160-(width/2),-(height + 10), width, height );
} Else if (deviceTilt. x> 0.5f ){
DollarView. frame = CGRectMake (-(width + 10), 240-(height/2), width, height );
} Else if (deviceTilt. x <-0.5f ){
DollarView. frame = CGRectMake (330,240-(height/2), width, height );
} Else {
Switch (RANDOM_INT (0, 3 )){
Case 0:
DollarView. frame = CGRectMake (-300,-300,100 * scale, 44 * scale );
Break;
Case 1:
DollarView. frame = CGRectMake (470,-150,100 * scale, 44 * scale );
Break;
Case 3:
DollarView. frame = CGRectMake (470,630,100 * scale, 44 * scale );
Break;
Default:
DollarView. frame = CGRectMake (-150,630,100 * scale, 44 * scale );
Break;
}
}
[Self addSubview: dollarView];
If (helpView)
[Self bringSubviewToFront: helpView];
[UIView beginAnimations: nil context: dollarView];
[UIView setAnimationDuration: 2];
DollarView. frame = CGRectMake (RANDOM_INT (-50,370), RANDOM_INT (-25,665), 100, 44 );
Int radians = RANDOM_INT (0,360) * 0.0174532925;
[DollarView setTransform: CGAffineTransformMakeRotation (radians)];
[UIView setAnimationDelegate: self];
[UIView commitAnimations];
BillCount ++;
[BillList addObject: dollarView];
If ([billList count]> = MAX_BILLS ){
UIImageView * oldBill = (UIImageView *) [billList objectAtIndex: 0];
[BillList removeObjectAtIndex: 0];
[UIView beginAnimations: nil context: oldBill];
[UIView setAnimationDuration: 2];
[OldBill setAlpha: 0.0];
[UIView setAnimationDelegate: self];
[UIView setAnimationDidStopSelector: @ selector (goPutThemBack: finished: context :)];
[UIView commitAnimations];
}
}