欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

iOS自带动画效果的实例代码

程序员文章站 2023-12-22 20:56:58
 1.普通动画: [uiview beginanimations:nil context:nil]; [uiview setanimationdura...

 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自带动画效果的实例代码,希望对大家有所帮助

上一篇:

下一篇: