iOS自带动画效果的实例代码
1.普通动画:
[UIViewbeginAnimations:nilcontext:nil]; [UIViewsetAnimationDuration:2]; frame.origin.x+=150; [imgsetFrame:frame]; [UIViewcommitAnimations];
2.连续动画(一系列图像):
NSArray*myImages=[NSArrayarrayWithObjects: [UIImageimageNamed:@"myImage1.png"], [UIImageimageNamed:@"myImage2.png"], [UIImageimageNamed:@"myImage3.png"], [UIImageimageNamed:@"myImage4.png"],nil]; UIImageView*myAnimatedView=[[UIImageViewalloc]initWithFrame:[selfbounds]]; myAnimatedView.animationImages=myImage; myAnimatedView.animationRepeatCount=0; [myAnimatedViewstartAnimating]; [selfaddSubview:myAnimatedView]; [myAnimatedViewrelease];
3.CATransitionPublicAPI:
CATransition*animation=[CATransitionanimation]; 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.layeraddAnimation:animationforKey:@"animation"];
4.UIViewAnimations动画:
[UIViewbeginAnimations:@"animationID"context:nil]; [UIViewsetAnimationDuration:0.5f]; [UIViewsetAnimationCurve:UIViewAnimationCurveEaseInOut]; [UIViewsetAnimationRepeatAutoreverses:NO]; //以下四种效果 /* [UIViewsetAnimationTransition:UIViewAnimationTransitionFlipFormLeftforView:self.viewcache:YES]; [UIViewsetAnimationTransition:UIViewAnimationTransitionFlipFormRightforView:self.viewcache:YES]; [UIViewsetAnimationTransition:UIViewAnimationTransitionCurlUpforView:self.viewcache:YES]; [UIViewsetAnimationTransition:UIViewAnimationTransitionCurlDownforView:self.viewcache:YES]; */
5.嵌套使用,先变大再消失
[UIViewanimateWithDuration:1.25aniamtions:^{ CGAffineTransformnewTRansform=CGAffineTransformMakeScale(1.2,1.2); [firstImageViewsetTransform:newTransform]; [secondImageViewsetTransform:newTransform]; completion:^(BOOLfinished){ [UIViewanimateWithDuration:1.2animations:^{ [firstImageViewsetAlpha:0]; [secondImageViewsetAlpha:0]; } completion:^(BOOLfinished){ [firstImageViewremoveFromSuperview]; [secondImageViewremoveFromSuperview]; } ]; } ];
以上所述是小编给大家介绍的iOS自带动画效果的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!