iOS开发中微信中语音播放的动画效果

先看效果图:
0.语音播放动画.gif
代码:
  LSVoiceView * voiceView = [[LSVoiceView alloc] initWithFrame:CGRectMake(200, 100, 200, 40)];
[self.view addSubview:voiceView];

我是自定义了一个播放语音动画的View。

自定义的该View中有两个值得一看的地方1.动画的实现 2.图片的防拉伸。

先看实现动画的代码

底部的绿色视图是一个UIImageView对象,闪动的视图也是一个UIImageView对象,闪动是因为该视图设置了三张不同的图片分别是


icon_voice_sender_1@2x.png
icon_voice_sender_2@2x.png
icon_voice_sender_3@2x.png
  _voiceStatusImageView.highlightedAnimationImages = @[image1, image2, image3];
    _voiceStatusImageView.animationDuration = 1.5;
    _voiceStatusImageView.animationRepeatCount = NSUIntegerMax;

先将这三张图片设置为该UIImageView对象的highlightedAnimationImages属性。

播放动画的代码
  - (void)startAnimation{
self.voiceStatusImageView.highlighted = YES;
[self.voiceStatusImageView startAnimating];
}
结束动画的代码
  - (void)stopAnimation{
self.voiceStatusImageView.highlighted = NO;
[self.voiceStatusImageView stopAnimating];
}

再看防图片布局拉伸的代码

背景图的原图是


bg_chat_me@2x.png

代码:

   [_voiceImageView setImage:[[UIImage imageNamed:@"bg_chat_me"] resizableImageWithCapInsets:UIEdgeInsetsMake(20, 8, 8, 20) resizingMode:UIImageResizingModeStretch]];

在设置完image之后使用了一个方法:resizableImageWithCapInsets,该方法的参数设置了不被拉伸的区域。至于两种模型
:UIImageResizingModeStretch、UIImageResizingModeTile我看到的效果是一样的。

demo地址:***https://gitee.com/liangsenliangsen/yuyinbofangdonghua/tree/master
本篇文章到这里就结束了,愿大家加班不多工资多,男同胞都有女朋友,女同胞都有男朋友。😊

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容