IOS 雪花飄落效果

m8x2 9年前發布 | 2K 次閱讀 Objective-C IOS

        UIImageView *peach2 = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"flower2"]];//聲明一個UIImageView對象,用來添加圖片  
        peach2.alpha = 0.8;//設置該view的alpha為0.5,半透明的  
        int xx = round(random()%2000);//隨機得到該圖片的x坐標  
        int yx = round(random()%2000);//這個是該圖片移動的最后坐標x軸的  
        int sx = random()%50+10;//這個是定義雪花圖片的大小  
        int spx = random()%5;//這個是速度  
        peach2.frame = CGRectMake(-xx, -10, sx, sx);//雪花開始的大小和位置  
        [view_bottom addSubview:peach2];//添加該view  
        [UIView animateWithDuration:10*spx  
                         animations:^{  
                             peach2.frame = CGRectMake(yx, self.view.frame.size.height, sx, sx);//設定該雪花最后的消失坐標  
                         } completion:^(BOOL finished) {  
                             [peach2 removeFromSuperview];  
                         }];  

 本文由用戶 m8x2 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!