IOS简单动画总结

IOS实现动画的几种简单方式:

1.通过QuadCurveMenuItem实现弹出按钮的效果

 NSMutableArray *items = [NSMutableArrayarray];

    for (int i = 1; i < 5; i++) {

        UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"home_h_btn%d.png", (5-i)]];

        QuadCurveMenuItem *item = [[QuadCurveMenuItemalloc] initWithImage:image

                                                          highlightedImage:image

                                                              ContentImage:image

                                                   highlightedContentImage:nil];

        [items addObject:item];

        [item release];

    }

    CGRect f = CGRectMake(60, 80,33, 33);

    HomeQuadCurveMenu *_menu = [[HomeQuadCurveMenualloc] initWithFrame:f menus:items];

    _menu.delegate = self;

    [_mainPage addSubview:_menu];

    [_menu release];

 

2.通过CABasicAnimation实现平移、旋转、放大

1.旋转

self.view.backgroundColor = [UIColorgreenColor];

CABasicAnimation *ani = [CABasicAnimationanimationWithKeyPath:@"transform.rotation.z"];

    ani.fromValue = [NSNumbernumberWithFloat:0];

    ani.toValue = [NSNumber numberWithFloat:M_PI*2];

    ani.autoreverses = NO;

    ani.duration = 10;

    ani.repeatCount = 10;

    

2.平移

    CABasicAnimation *ani2 = [CABasicAnimationanimationWithKeyPath:@"transform.translation.x"];

    ani2.fromValue = [NSNumber numberWithFloat:0];

    ani2.toValue = [NSNumber numberWithFloat:300];

    ani2.autoreverses = NO;

    ani2.duration = 10;

    ani2.repeatCount = 10;

3.放大 

    CABasicAnimation *ani3 = [CABasicAnimationanimationWithKeyPath:@"transform.scale"];

    ani3.fromValue = [NSNumber numberWithFloat:0];

    ani3.toValue = [NSNumber numberWithDouble:20];

    ani3.autoreverses = NO;

    ani3.duration = 10;

    ani3.repeatCount = 10;

    ani3.speed = 0.5f;

    

    [_rotateImgView.layer addAnimation:ani forKey:@"rotate"];

    [_rotateImgView2.layer addAnimation:ani2 forKey:@"animateLayer"];

    [_rotateImgView3.layer addAnimation:ani3 forKey:@"sss"];

    [_rotateImgView release];

    [_rotateImgView2 release];

    [_rotateImgView3 release];

 

3.移动页面位置的动画

    void (^animations)(void) = ^{

self.mainPage.transform  = CGAffineTransformMakeTranslation(199, 0);};

    void (^complete)(BOOL) = ^(BOOL finished) {

        self.mainPage.transform  = CGAffineTransformMakeTranslation(0, 0);

};

    [UIViewanimateWithDuration:2animations:animations completion:complete];

这种动画的书写方式也可以是

[UIViewanimateWithDuration:2animations:^{

        self.mainPage.transform  = CGAffineTransformMakeTranslation(199, 0);

    } completion:^(BOOL finished) {

        [UIViewanimateWithDuration:0.2delay:0.1foptions:UIViewAnimationOptionCurveEaseInanimations:^{

            self.mainPage.transform  = CGAffineTransformMakeTranslation(0, 0);

        } completion:^(BOOL finished) {

            

        }];

    }];

4.创建简单的动画

    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    //UIView开始动画,第一个参数是动画的标识,第二个参数附加的应用程序信息用来传递给动画代理消息
    [UIView beginAnimations:@"View Flip" context:nil];
    //动画持续时间
    [UIView setAnimationDuration:1.25];
    //设置动画的回调函数,设置后可以使用回调方法
    [UIView setAnimationDelegate:self];
    //设置动画曲线,控制动画速度
    [UIView  setAnimationCurve: UIViewAnimationCurveEaseInOut];
    //设置动画方式,并指出动画发生的位置
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view  cache:YES];
    //提交UIView动画
    [UIView commitAnimations];

5.自定义cell时可通过以下方法绘制简单的图形

- (void)drawRect:(CGRect)rect

{

    CGRect fillRect = CGRectMake(10, 10, 298, cellHeight-20);

    float radius = 3;

    UIBezierPath *fillPath = [UIBezierPath bezierPathWithRoundedRect:fillRect cornerRadius:radius];

    [[UIColor whiteColor] setFill];

    [RgbHex2UIColor(237, 237, 237) setStroke];

    [fillPath setLineWidth:2.0f];

    [fillPath stroke];

[fillPath fill];

    

}

你可能感兴趣的:(IOS动画)