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语言的函数调用请看这里 ) ...
随机推荐
- java中的等于
数字的比较等于用“==” 不等于用“!=” 字符的比较等于用“.equals”不等于用”!s1.equals(s2)“
- 明晨HOSTS编辑器mcHostsEdtor与火狐HostAdmin配合使用
在开发过程中,需要经常切换环境开发.测试.Stage和正式环境,甚为麻烦. 后来找到了HOST切换工具mcHostsEdtor工具快速切换host,但浏览器比如有HOST缓存,后来同事推荐FireFo ...
- PHP打印测试,PHP调试技巧
第一步: 在 php.ini 中,将 display_errors 设置为 On: 第二步: 在 框架的 开始处,添加如下代码: <?php if (isset($_GET['debug'])) ...
- Nginx反向代理+keepalived
环境两台LB(nginx).两台web(nginx/apache都行) 安装httpd web01 [root@web01 /]# /etc/init.d/iptables stop iptables ...
- BZOJ1562——[NOI2009]变换序列
1.题意:题意有些难理解 2.分析:我们发现如果要求判断是否合法的话就so easy了,二分图匹配即可,但是我们发现要求输出字典序最小的,那么我们在匈牙利的时候就倒着枚举,另外邻接表中的边一定要排好序 ...
- ICMP的应用--Traceroute
Traceroute是用来侦测主机到目的主机之间所经路由情况的重要工具,也是最便利的工具.前面说到,尽管ping工具也可以进行侦测,但是,因为ip头的限制,ping不能完全的记录下所经过的路由器.所以 ...
- python3 爬虫
保存当前cookie到本地 import urllib.request as ur import http.cookiejar as hc url='http://www.xxxx.com/admin ...
- PHPStorm XDebug的安装
环境: 我的系统: 4.4.0-43-generic #63-Ubuntu SMP Wed Oct 12 13:48:03 UTC 2016 x86_64 x86_64 x86_64 GNU/Linu ...
- 【Network】UDP 大包怎么发? MTU怎么设置?
这里主要用UDP来发送视频,当发送的数据大于1500时分包发送,保证每包小于1500.发送好办,分割后循环发就可以了,关键是接收时的处理.先做一下处理的方法 :发送时每包上面加上标识,比如RTP的做法 ...
- SQL Server 日期和时间函数
http://www.cnblogs.com/adandelion/archive/2006/11/08/554312.html 1.常用日期方法(下面的GetDate() = '2006-11-08 ...