iOS自带动画效果的实例代码
2019/7/9 23:03:15
本文主要是介绍iOS自带动画效果的实例代码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
1.普通动画:
[UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:2]; frame.origin.x += 150; [img setFrame:frame]; [UIView commitAnimations];
2.连续动画(一系列图像):
NSArray *myImages = [NSArray arrayWithObjects: [UIImage imageNamed:@"myImage1.png"], [UIImage imageNamed:@"myImage2.png"], [UIImage imageNamed:@"myImage3.png"], [UIImage imageNamed:@"myImage4.png"], nil]; UIImageView *myAnimatedView = [[UIImageView alloc] initWithFrame:[self bounds]]; myAnimatedView.animationImages = myImage; myAnimatedView.animationRepeatCount = 0; [myAnimatedView startAnimating]; [self addSubview:myAnimatedView]; [my AnimatedView release];
3.CATransition Public API:
CATransition *animation = [CATransition animation]; animation.duration = 0.5f; animation.timingFunction = UIViewAnimationCurveEaseInOut; animation.fillMode = KCAFillModeForwards; //各种动画效果 /* KCATransitionFade; KCATransitionMoveIn; KCATransitionPush; KCATransitionReveal; */ /* KCATransitionFromeRight; KCATransitionFromLeft; KCATransitionFormTop; kCATransitionFromButtons; */ //各种组合 animation.type = KCATransitionPush; animation.subtype = KCATransitionFromRight; [self.view.layer addAnimation:animation forKey:@"animation"];
4.UIView Animations动画:
[UIView beginAnimations:@"animationID" context:nil]; [UIView setAnimationDuration:0.5f]; [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIView setAnimationRepeatAutoreverses:NO]; //以下四种效果 /* [UIView setAnimationTransition:UIViewAnimationTransitionFlipFormLeft forView:self.view cache:YES]; [UIView setAnimationTransition:UIViewAnimationTransitionFlipFormRight forView:self.view cache:YES]; [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES]; [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES]; */
5.嵌套使用,先变大再消失
[UIView animateWithDuration:1.25 aniamtions:^{ CGAffineTransform newTRansform = CGAffineTransformMakeScale(1.2, 1.2); [firstImageView setTransform:newTransform]; [secondImageView setTransform:newTransform]; completion:^(BOOL finished){ [UIView animateWithDuration:1.2 animations:^{ [firstImageView setAlpha:0]; [secondImageView setAlpha:0]; } completion:^(BOOL finished){ [firstImageView removeFromSuperview]; [secondImageView removeFromSuperview]; } ]; } ];
以上所述是小编给大家介绍的iOS自带动画效果的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对找一找教程网网站的支持!
这篇关于iOS自带动画效果的实例代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-11-12Axios库资料:新手入门必读教程
- 2024-11-11Axios库项目实战:新手入门教程
- 2024-09-29Axios库教程:初学者必备指南
- 2024-08-29Axios库资料:新手入门指南与基本使用教程
- 2024-03-14system bios shadowed
- 2024-03-14gabios
- 2024-02-07iOS应用提交上架的最新流程
- 2024-02-06打包 iOS 的 IPA 文件
- 2023-12-07uniapp打包iOS应用并通过审核:代码混淆的终极解决方案 ?
- 2023-11-25uniapp IOS从打包到上架流程(详细简单) 原创