iOS UIView 动画浅谈
UIView 等会效果简单实现,哪一个登录页面的demo来举例子吧.
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations;
UIView的一个类方法,可以看出这个方法里面只有两个参数:
duration: 动画持续时间;
animations:动画闭包,在这个闭包中你可以改变UIView的各种动画属性(这个方法中可以同时改变多个属性);
// 闭包里面是textField最终出现的位置,前提是你已经设置好了textField的位置.
[UIView animateWithDuration:0.5 animations:^{
self.emailTextField.frame = CGRectMake(, self.userImg.frame.origin.y + self.userImg.bounds.size.height + , screen_width - , );
self.pwdTextField.frame = CGRectMake(, self.emailTextField.frame.origin.y + self.emailTextField.bounds.size.height, screen_width - , ); } completion:nil];


这个就是上面的代码动画出现的过程截图,emailText 和 pwdTextField 分别重两次移动到中间位置;
+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^ __nullable)(BOOL finished))completion;
这个方法多了几个参数:
delay:延时时间;
options:动画效果,比如重复动画、前后运动等;
[UIView animateWithDuration:0.5 delay: options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.emailTextField.frame = CGRectMake(, self.userImg.frame.origin.y + self.userImg.bounds.size.height + , screen_width - , );
} completion:nil];
CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI);
[UIView animateWithDuration:0.5 delay:0.3 options:UIViewAnimationOptionCurveLinear animations:^{
self.pwdTextField.frame = CGRectMake(, self.emailTextField.frame.origin.y + self.emailTextField.bounds.size.height, screen_width - , );
self.userImg.transform = rotation;
} completion:nil];
这个过程里有头像的转动,emailText 和 pwdTextField 分别重两次移动到中间位置;


这两个添加动画效果的方法的代码附在下面:
//
// ViewController.m
// loginDemo20160330
//
// Created by miaoguodong on 16/3/30.
// Copyright © 2016年 miaoguodong. All rights reserved.
// #import "ViewController.h"
#define screen_width ([UIScreen mainScreen].bounds.size.width)
#define screen_height ([UIScreen mainScreen].bounds.size.height)
@interface ViewController () @property (weak, nonatomic) IBOutlet UIImageView *loginBgImg;
@property (weak, nonatomic) IBOutlet UIImageView *userImg; @property (weak, nonatomic) IBOutlet UITextField *emailTextField;
@property (weak, nonatomic) IBOutlet UITextField *pwdTextField; @end @implementation ViewController
- (void)dealloc
{
self.loginBgImg = nil;
self.userImg = nil;
self.emailTextField = nil;
self.pwdTextField = nil;
} - (void)viewDidLoad {
[super viewDidLoad]; self.loginBgImg.frame = CGRectMake(, , screen_width, screen_height);
self.loginBgImg.image = [UIImage imageNamed:@"BgImage"]; self.userImg.frame = CGRectMake((self.loginBgImg.bounds.size.width - )/, , , );
self.userImg.image = [UIImage imageNamed:@"usrIcon"]; self.emailTextField.frame = CGRectMake(screen_width, self.userImg.frame.origin.y + self.userImg.bounds.size.height + , screen_width - , );
self.pwdTextField.frame = CGRectMake(-screen_width, self.emailTextField.frame.origin.y + self.emailTextField.bounds.size.height, screen_width - , );
// self.emailTextField.frame = CGRectMake(30, self.userImg.frame.origin.y + self.userImg.bounds.size.height, screen_width - 60, 40);
// self.pwdTextField.frame = CGRectMake(30, self.emailTextField.frame.origin.y + self.emailTextField.bounds.size.height, screen_width - 60, 40); UIView *emailLeftView = [[UIView alloc]initWithFrame:CGRectMake(, , self.emailTextField.bounds.size.height, self.emailTextField.bounds.size.height)];
UIImageView *eleftImg = [[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
eleftImg.image = [UIImage imageNamed:@"user"];
[emailLeftView addSubview:eleftImg];
self.emailTextField.leftView = emailLeftView;
self.emailTextField.leftViewMode = UITextFieldViewModeAlways; UIView *pwdLeftView = [[UIView alloc]initWithFrame:CGRectMake(, , self.pwdTextField.bounds.size.height, self.pwdTextField.bounds.size.height)];
UIImageView *pleftImg = [[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
pleftImg.image = [UIImage imageNamed:@"pwd"];
[pwdLeftView addSubview:pleftImg];
self.pwdTextField.leftView = pwdLeftView;
self.pwdTextField.leftViewMode = UITextFieldViewModeAlways; // 简单设置 text输入框出现 // [UIView animateWithDuration:0.5 animations:^{
// self.emailTextField.frame = CGRectMake(30, self.userImg.frame.origin.y + self.userImg.bounds.size.height + 30, screen_width - 60, 40);
// self.pwdTextField.frame = CGRectMake(30, self.emailTextField.frame.origin.y + self.emailTextField.bounds.size.height, screen_width - 60, 40);
//
// } completion:nil]; // 设置 text输入框有动画效果的飞入
[UIView animateWithDuration:0.5 delay: options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.emailTextField.frame = CGRectMake(, self.userImg.frame.origin.y + self.userImg.bounds.size.height + , screen_width - , );
} completion:nil];
CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI);
[UIView animateWithDuration:0.5 delay:0.3 options:UIViewAnimationOptionCurveLinear animations:^{
self.pwdTextField.frame = CGRectMake(, self.emailTextField.frame.origin.y + self.emailTextField.bounds.size.height, screen_width - , );
self.userImg.transform = rotation;
} completion:nil]; // Do any additional setup after loading the view, typically from a nib.
} - (void)viewWillAppear:(BOOL)animated
{ } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
iOS UIView 动画浅谈的更多相关文章
- iOS 自定义转场动画浅谈
代码地址如下:http://www.demodashi.com/demo/11612.html 路漫漫其修远兮,吾将上下而求索 前记 想研究自定义转场动画很久了,时间就像海绵,挤一挤还是有的,花了差不 ...
- iOS开发之浅谈MVVM的架构设计与团队协作
今天写这篇博客是想达到抛砖引玉的作用,想与大家交流一下思想,相互学习,博文中有不足之处还望大家批评指正.本篇博客的内容沿袭以往博客的风格,也是以干货为主,偶尔扯扯咸蛋(哈哈~不好好工作又开始发表博客啦 ...
- iOS应用架构浅谈
(整理至http://www.cocoachina.com/ios/20150414/11557.html) 缘由 从事iOS工作一年多了,主要从事QQ钱包SDK开发和财付通app维护,随着对业务的慢 ...
- iOS - UIView 动画
1.UIView 动画 核心动画 和 UIView 动画 的区别: 核心动画一切都是假象,并不会真实的改变图层的属性值,如果以后做动画的时候,不需要与用户交互,通常用核心动画(转场). UIView ...
- iOS UIView动画效果 学习笔记
//启动页动画 UIImageView *launchScreen = [[UIImageView alloc]initWithFrame:[UIScreen mainScreen].bounds]; ...
- IOS UIView动画(封装动画)
● UIKit直接将动画集成到UIView类中,当内部的一些属性发生改变时,UIView 将为这些改变提供动画支持 ● 执行动画所需要的工作由UIView类自动完成,但仍要在希望执行动画时通知视 图, ...
- iOS 应用架构浅谈
当我们讨论客户端应用架构的时候,我们在讨论什么? 其实市面上大部分应用不外乎就是颠过来倒过去地做以下这些事情: 简单来说就是调API,展示页面,然后跳转到别的地方再调API,再展示页面. App确实就 ...
- iOS之多线程浅谈
1)并发和并行的区别 在软件开发中不可避免的会遇到多线程的问题,在iOS客户端开发(或者.NET的winform或者wpf这样的cs程序)中就更不可避免的会用到多线程,在bs类型的web项目中要考虑一 ...
- iOS之RunTime浅谈
首先说一下什么是runtime:RunTime简称运行时.就是系统在运行的时候的一些机制,其中最主要的是消息机制.对于C语言,函数的调用 在编译的时候会决定调用哪个函数( C语言的函数调用请看这里 ) ...
随机推荐
- [Head First设计模式]云南米线馆中的设计模式——模版方法模式
系列文章 [Head First设计模式]山西面馆中的设计模式——装饰者模式 [Head First设计模式]山西面馆中的设计模式——观察者模式 [Head First设计模式]山西面馆中的设计模式— ...
- double 和 float
对编程人员来说,double 和 float 的区别是double精度高,有效数字16位,float精度7位.但double消耗内存是float的两倍,double的运算速度比float慢得多,C语言 ...
- jsp 入门 cookie session
Java Server Page ==> 服务器端的动态页面资源.用来做显示的功能. JSP构成 ==> HTML 脚本代码 标签构成. JSP 原理 ==> 实际上就是 servl ...
- mysql连结查询
2016年4月13日 18:08:22 星期三 union 会生成临时表, 然后一同取出合并 join 或子查询, 会生成临时表进行嵌套循环 临时表, 缺点就是没有索引
- [mysql]数据库基础知识
数据库管理系统DBMS 软件 bin config db (保存数据) 写程序: 数据库在本地 找到目录 添加数据 数据库在远程 socket连接上远程机器 socket发送命令 需要做的事情 程序 ...
- Mac下Boost环境搭建
Boost,一个功能强大.跨平台.开源而且免费的C++程序库,可以在其官网了解更多:http://www.boost.org,C++标准经过不断的升级完善,现在已经功能越来越吸引人了,Boost开发过 ...
- 3.Java异常进阶
3.JAVA异常进阶 1.Run函数中抛出的异常 1.run函数不会抛出异常 2.run函数的异常会交给UncaughtExceptionhandler处理 3.默认的UncaughtExceptio ...
- mac
command+R 刷新页面 command+shift+C 我的电脑 finder->应用程序 -> 实用程序 -> 终端 打开 cmd command+F3 显示桌面 comma ...
- Channel
提起Channel,JDK的NIO类库的重要组成部分,就是提供了java.nio.SocketChannel和java.nio.ServerSocketChannel,用于非阻塞的I/O操作. 类似于 ...
- 《DSP using MATLAB》示例Example5.15
代码: x1 = [1,2,2]; x2 = [1,2,3,4]; y1 = circonvt(x1,x2,5); % N = 5 n1 = 0:1:length(x1)-1; n2 = 0:1:le ...