UIView animation动画、AvAudioPlayer声效、定时器timer

原创文章
声明:作者声明此文章为原创,未经作者同意,请勿转载,若转载,务必注明本站出处,本平台保留追究侵权法律责任的权利。
全栈老韩
全栈工程师,擅长iOS App开发、前端(vue、react、nuxt、小程序&Taro)开发、Flutter、React Native、后端(midwayjs、golang、express、koa)开发、docker容器、seo优化等。

声效:

复制代码
NSString *mp3String=[[NSBundle mainBundle]pathForResource:@"beauty_ok2" ofType:@"mp3"];
    NSURL *url=[NSURL fileURLWithPath:mp3String];
    NSData *data=[[NSData alloc]initWithContentsOfURL:url];
    _audioPlayer=[[AVAudioPlayer alloc]initWithData:data error:nil];

UIView animation动画:

复制代码
[UIView animateWithDuration:1.2 animations:^{
        for(int i=0; i<12; i++)
        {
            self.starImageView = (UIImageView *)[self.view viewWithTag:STARIMAGEVIEWTAG+i];
            self.starImageView.transform = CGAffineTransformMakeRotation(3.0);
            self.starImageView.alpha = 0;
            [_audioPlayer prepareToPlay];
            [_audioPlayer play];
            
        }
    } completion:^(BOOL finished) {
        for(int i=0; i<12; i++)
        {
            self.starImageView = (UIImageView *)[self.view viewWithTag:STARIMAGEVIEWTAG+i];
            [self.starImageView removeFromSuperview];
        }
    }];

定时器timer:

复制代码
starsAnimationTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(doStarsAnimation) userInfo:nil repeats:NO];
[starsAnimationTimer invalidate];
    starsAnimationTimer = nil;

暂无评论,快来发表第一条评论吧