#import "ViewController.h"

@interface ViewController ()
{
    UIButton *btn;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    btn=[UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame=CGRectMake(30, 30, 50, 50);
    btn.backgroundColor=[UIColor redColor];
    [btn setTitle:@"按钮" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(btnclick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];

}
//UIViewAnimationWithBlocks
-(void)btnclick:(id)sender
{
   // 此方法参数1:动画时长 参数2:修改的View的属性
    [UIView animateWithDuration:2 animations:^{
        btn.backgroundColor=[UIColor blackColor];
    }];

   //此方法参数1:动画时长 参数2:修改的View的属性 参数3:动画完成的回调
   [UIView animateWithDuration:3 animations:^{
       btn.backgroundColor=[UIColor redColor];
   } completion:^(BOOL finished) {
       NSLog(@"completion1");
   }];
   /* UIViewAnimationOptionLayoutSubviews //提交动画的时候布局子控件,表示子控件将和父控件一同动画。

    UIViewAnimationOptionAllowUserInteraction //动画时允许用户交流,比如触摸

    UIViewAnimationOptionBeginFromCurrentState //从当前状态开始动画

    UIViewAnimationOptionRepeat //动画无限重复

    UIViewAnimationOptionAutoreverse //执行动画回路,前提是设置动画无限重复

    UIViewAnimationOptionOverrideInheritedDuration //忽略外层动画嵌套的执行时间

    UIViewAnimationOptionOverrideInheritedCurve //忽略外层动画嵌套的时间变化曲线

    UIViewAnimationOptionAllowAnimatedContent //通过改变属性和重绘实现动画效果,如果key没有提交动画将使用快照

    UIViewAnimationOptionShowHideTransitionViews //用显隐的方式替代添加移除图层的动画效果

    UIViewAnimationOptionOverrideInheritedOptions //忽略嵌套继承的选项

    //时间函数曲线相关

    UIViewAnimationOptionCurveEaseInOut //时间曲线函数,由慢到快

    UIViewAnimationOptionCurveEaseIn //时间曲线函数,由慢到特别快

    UIViewAnimationOptionCurveEaseOut //时间曲线函数,由快到慢

    UIViewAnimationOptionCurveLinear //时间曲线函数,匀速

    //转场动画相关的

    UIViewAnimationOptionTransitionNone //无转场动画

    UIViewAnimationOptionTransitionFlipFromLeft //转场从左翻转

    UIViewAnimationOptionTransitionFlipFromRight //转场从右翻转

    UIViewAnimationOptionTransitionCurlUp //上卷转场

    UIViewAnimationOptionTransitionCurlDown //下卷转场

    UIViewAnimationOptionTransitionCrossDissolve //转场交叉消失

    UIViewAnimationOptionTransitionFlipFromTop //转场从上翻转

    UIViewAnimationOptionTransitionFlipFromBottom //转场从下翻转
    */
    //参数1 动画时长 参数2 延迟时间 参数3 枚举见上面注释 参数4 改变View属性 参数5 动画完成时回调
    [UIView animateKeyframesWithDuration:2 delay:2 options:UIViewKeyframeAnimationOptionBeginFromCurrentState animations:^{
          btn.backgroundColor=[UIColor greenColor];
            CGRect frame=btn.frame;
            if (frame.origin.x<self.view.frame.size.width-20) {
                frame.origin.x+=20;
            }
            else
            {
                frame.origin.x=0;

            }
            btn.frame=frame;
    } completion:^(BOOL finished) {
        NSLog(@"completion2");
    }];
    //转场动画
    [UIView transitionFromView:self.view toView:btn duration:5 options:UIViewAnimationOptionTransitionCurlDown completion:^(BOOL finished) {
        NSLog(@"completion3");
    }];
   [UIView transitionWithView:self.view duration:5 options:UIViewAnimationOptionTransitionFlipFromBottom animations:^{
       btn.backgroundColor=[UIColor redColor];
   } completion:^(BOOL finished) {
       NSLog(@"completion4");
   }];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

UIView动画下的更多相关文章

  1. UIView动画效果

    做出UI界面,实现程序功能,是重中之重,但是通过动画提升使用体验,一般人应该不会拒绝吧. 那么问题又来了,怎么做? 一: 稳扎稳打: 一步一步来吧,毕竟,心急吃不了热豆腐. 1.开启一个动画 2,设置 ...

  2. 个人学习对UIView动画的总结

    我的博客之前已经开通五个月了,但是一直没有写东西.一是不敢写,二是也不知道写啥.毕竟是一个刚刚入行大半年的菜鸟,现在总想通过各种办法提高自己.之前总感觉用到一些东西,只是当时搞懂了一点,加上并没有总结 ...

  3. UIView动画学习笔记

    UIView的动画是通过修改控件的属性来达到动画的效果,如:渐变, 移动. 废话不多说,直接上代码: - (void)loadView{ [super loadView]; _leftView = [ ...

  4. iOS动画篇:UIView动画

    iOS的动画效果一直都很棒很,给人的感觉就是很炫酷很流畅,起到增强用户体验的作用.在APP开发中实现动画效果有很多种方式,对于简单的应用场景,我们可以使用UIKit提供的动画来实现. UIView动画 ...

  5. UIView动画补充

    我自己的总结: // 第一种: Duration 时间 animations:动画体 /* [UIView animateWithDuration:4 animations:^{ CGRect rec ...

  6. 快速上手UIView动画

    UIView动画有两种使用方法 UIView [begin commit]模式 //动画开始标记 [UIView beginAnimations:@"changeframe" co ...

  7. iOS核心动画以及UIView动画的介绍

    我们看到很多App带有绚丽狂拽的特效,别出心裁的控件设计,很大程度上提高了用户体验,在增加了实用性的同时,也赋予了app无限的生命力.这些华丽的效果很多都是基于iOS的核心动画原理实现的,本文介绍一些 ...

  8. 转一篇简洁的UIView动画编程方法

    iOS  中的 UIView 动画编程其实还是很简单的,像 CSS3 一样,在给定的时间内完成状态连续性的变化呈现.比如背景色,Frame 大小,位移.翻转,特明度等. 以前我使用的编程方式都是用下面 ...

  9. UIView动画

    UIView动画 一.commitAnimations方式使用UIView动画 1.commitAnimations方式使用UIView动画 [UIView beginAnimations:@&quo ...

随机推荐

  1. NET 获取实例所表示的日期是星期几

    获取日期枚举,可以根据switch去进行操作 DateTime.Now.DayOfWeek

  2. JQuery的页面操作

    window.location = "http://www.xxxxxxxx.net" 跳转后有后退功能 其实应该是 window.location.hrefwindow.loca ...

  3. C++获取本机IP地址信息

    #include<winsock2.h> #include<iostream> #include<string> using namespace std; #pra ...

  4. JavaScript基础(2)-DOM

    一.伪数组arguments arguments代表的是实参,有个讲究的地方是:arguments只在函数中使用. 1.返回函数实参的个数:arguments.length,例如: fn(2,4); ...

  5. 修改ssh远程默认端口

    修改ssh远程默认端口 Linuxssh端口修改 1. 修改ssh配置文件 [root@distzabbix ~]# vim /etc/ssh/sshd_config 找到第17行附近#Port 22 ...

  6. VSTO:C#获取文档控件的值

    基础知识准备: VSTO入门 创建Excel解决方案   string[] inputfileNames = { @"C:\1.xls", @"C:\2.xls" ...

  7. 设置iptables NAT出外网

    有时候云上部署环境,不能动态自设路由,没有公网ip地址的服务器,只能通过NAT的方式出外网,下面就记录一下设置过程. 当前状态 服务器A只有一个内网IP,不能上外网,内网IP与服务器B内网相通:服务器 ...

  8. flask加vue 动画 加载更多

    曾经使用flask_paginate(地址:https://blog.csdn.net/qq_42239520/article/details/80378095)进行分页,现在又想新的想法,怎么才能和 ...

  9. ajex 相关参数

    1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如 ...

  10. (转)Python3之shutil模块

    原文:https://www.cnblogs.com/wang-yc/p/5625046.html 一. 简介 shutil 是高级的文件,文件夹,压缩包处理模块. 二. 使用 shutil.copy ...