- (IBAction)onButtonClickHandler:(id)sender {
UIImageView *heartImageView = [[UIImageViewalloc]initWithFrame:CGRectMake(100.0, 100.0, 50.0, 50.0)];
[self.view addSubview:heartImageView];
NSMutableArray *images = [[NSMutableArrayalloc]initWithCapacity:7];
for (int i=1; i<=7; i++) {
[images addObject:[UIImageimageNamed:[NSStringstringWithFormat:@"xxx%d.png",i]]];
}
heartImageView.animationImages = images;
heartImageView.animationDuration = 0.4 ;
heartImageView.animationRepeatCount = 1;
[heartImageView startAnimating];
[NSTimer scheduledTimerWithTimeInterval:heartImageView.animationDuration
target:self
selector:@selector(onFrameAnimationFinished:)
userInfo:heartImageView
repeats:NO];
}
- (void)onFrameAnimationFinished:(NSTimer *)timer{
UIImageView * imageView = (UIImageView *)[timeruserInfo];
[imageView removeFromSuperview];
}
本文介绍了一个使用Objective-C在iOS应用中实现动态心形图标的方法。通过加载一系列PNG图片作为动画帧,并利用UIImageView的animationImages属性播放这些帧来展示动画效果。文章还展示了如何通过NSTimer在动画结束后移除图标。

4582

被折叠的 条评论
为什么被折叠?



