zoukankan      html  css  js  c++  java
  • UIKit Animation

    UIKit Animation


    1.属性动画

    - (void)changeFrameAnimation {
    [UIView beginAnimations:@"frameAnimation" context:nil];
    [UIView setAnimationDuration:0.8];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationWillStartSelector:@selector(startAnimation:)];
    [UIView setAnimationDidStopSelector:@selector(stopAnimation:)];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationRepeatCount:1];

    // [UIView setAnimationRepeatAutoreverses:YES];

    self.secondView.frame = self.firstView.frame;

    [UIView commitAnimations];
    }

    2.Transition 提供了一个图层变化的过渡效果,它能影响图层的整个内容

    - (void)transitionAnimation {
    [UIView beginAnimations:@"frameAnimation" context:nil];
    [UIView setAnimationDuration:0.8];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationWillStartSelector:@selector(startAnimation:)];
    [UIView setAnimationDidStopSelector:@selector(stopAnimation:)];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];

    [UIView setAnimationRepeatCount:1];

    self.firstView.backgroundColor = [UIColor purpleColor];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.firstView cache:YES]; // 转场效果,forView 动画作用对象

    [UIView commitAnimations];
    }
    1. Block Animation
    - (void)block1 {
    [UIView animateWithDuration:0.8 animations:^{
    self.secondView.frame = self.firstView.frame;
    }];
    }

    - (void)block2 {
    [UIView animateWithDuration:0.8 animations:^{
    self.secondView.frame = self.firstView.frame;
    } completion:^(BOOL finished) {
    NSLog(@"complete blockAnimation");
    }];
    }

    - (void)block3 {
    [UIView animateWithDuration:0.8 delay:3.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
    self.secondView.frame = self.firstView.frame;
    } completion:^(BOOL finished) {
    NSLog(@"options");
    }];
    }

    4.SpringAnimation

    /**
    * @author Jack Lee, 16-05-16 15:05:05
    *
    * @brief after iOS7.0
    */

    - (void)springAnimation {
    // damping:取值范围0~1,值越小振荡越明显
    // velocity:初始速度,越大越快
    [UIView animateWithDuration:0.8 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:10 options:UIViewAnimationOptionCurveLinear animations:^{
    self.secondView.frame = self.firstView.frame;
    } completion:^(BOOL finished) {
    NSLog(@"complete spring");
    }];
    }

    5.关键帧动画

    /**
    * @author Jack Lee, 16-05-16 15:05:00
    *
    * @brief after iOS7.0
    */

    - (void)keyFrameAnimation {
    [UIView animateKeyframesWithDuration:4 delay:0 options:UIViewKeyframeAnimationOptionCalculationModeLinear animations:^{
    [UIView addKeyframeWithRelativeStartTime:0 relativeDuration:1 animations:^{
    self.firstView.backgroundColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1];
    }];

    [UIView addKeyframeWithRelativeStartTime:1 relativeDuration:1 animations:^{
    self.firstView.backgroundColor = [UIColor colorWithRed:0.8 green:0.6 blue:0.6 alpha:1];
    }];

    [UIView addKeyframeWithRelativeStartTime:2 relativeDuration:1 animations:^{
    self.firstView.backgroundColor = [UIColor colorWithRed:0.8 green:0.4 blue:0.4 alpha:1];
    }];

    [UIView addKeyframeWithRelativeStartTime:3 relativeDuration:1 animations:^{
    self.firstView.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:1];
    }];

    } completion:^(BOOL finished) {
    NSLog(@"complete keyframe animation");
    }];
    }
    1. Transition过渡动画二
    - (void)block3 {
    [UIView transitionWithView:self.firstView duration:0.8 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^{
    self.firstView.backgroundColor = [UIColor colorWithRed:0.2 green:0.5 blue:0.7 alpha:1];
    } completion:^(BOOL finished) {
    NSLog(@"complete block3");
    }];
    }

    - (void)block4 {
    UILabel *l = [[UILabel alloc] initWithFrame:self.firstView.frame];
    l.font = [UIFont systemFontOfSize:30];
    l.textColor = [UIColor orangeColor];
    l.textAlignment = NSTextAlignmentCenter;
    l.text = @"翻转";

    [UIView transitionFromView:self.firstView toView:l duration:0.8 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
    NSLog(@"from to complete");
    }];

    }
     
  • 相关阅读:
    迅为i.MX8M开发板Linux安卓9.0系统,四核CortexA53,单核CortexM4
    迅为龙芯2K1000开发板虚拟机ubuntu安装SSH服务
    迅为i.MX8MM开发板虚拟机Vmware的安装
    迅为龙芯2K1000开发板虚拟机ubuntu安装vscode
    归并排序XCoderLiu
    关于API中窗口子类化及超类化整理
    STL中最流行类模板vector
    andbook
    Navigation Failed: Cannot Find Application\HTML\1033\default.htm 错误解决办法
    html 播放音乐
  • 原文地址:https://www.cnblogs.com/buakaw/p/5725674.html
Copyright © 2011-2022 走看看