当前位置:编程学习 > wap >>

ios 美元飘落效果的demo

demo功能:ios 美元飘落效果的demo 。

demo说明:美元飘落效果demo ,可以多指触控,触控点越多,飘落的美元面额越大。主要代码在:MainView.m中。

demo截屏:

 

 


demo代码说明:


[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; 
    } 
    //以上是检测触点,并分配不同的美元图片  
    // for effect only draw one 2 dollar bill by resetting billIndex  
    if (billIndex == 2) 
        billIndex = 1; 
    //以下是动画部分的核心代码  
    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]; 
     

补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,