IOS UI动画与手势的基本使用
来源:互联网 发布:惠普2025网络设置 编辑:程序博客网 时间:2024/04/28 18:44
#import "UIViewAnimation.h"
#import "UIImageAnimatioController.h"
@interface UIViewAnimation ()
{
UIView * _blackRect;
}
@end
@implementation UIViewAnimation
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"动画";
UIBarButtonItem * nextPage = [[UIBarButtonItem alloc]initWithTitle:@"下一页" style:UIBarButtonItemStylePlain target:self action:@selector(pressedNext)];
self.navigationItem.rightBarButtonItem = nextPage;
UIBarButtonItem * backItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:nil];//上一个视图控制器决定下一个视图控制器的返回按钮
self.navigationItem.backBarButtonItem = backItem;
_blackRect = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
_blackRect.backgroundColor = [UIColor blackColor];
_blackRect.layer.cornerRadius = 3;
[self.view addSubview:_blackRect];
#pragma mark - 添加点击手势识别器
UITapGestureRecognizer * tapGR = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(precessTap)];
tapGR.numberOfTapsRequired = 1;//设置点击次数
tapGR.numberOfTouchesRequired = 1;//设置手指个数
[_blackRect addGestureRecognizer:tapGR];//添加
#pragma mark - 添加滑动手势识别器
UISwipeGestureRecognizer * swipeGR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(precessTap:)];
swipeGR.direction = UISwipeGestureRecognizerDirectionUp;//设置手势识别器滑动方向(默认是右滑)
swipeGR.numberOfTouchesRequired = 1;//设置手指数量
[self.view addGestureRecognizer:swipeGR];
}
- (void)precessTap:(UIGestureRecognizer *)sender
{
if ([sender isKindOfClass:[UITapGestureRecognizer class]]) {
NSLog(@"是点击手势");
}else if ([sender isKindOfClass:[UISwipeGestureRecognizer class]]) {
NSLog(@"是滑动手势");
}
}
- (void)pressedNext
{
UIImageAnimatioController * imageAnimation = [[UIImageAnimatioController alloc] init];
[self.navigationController pushViewController:imageAnimation animated:YES];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
}
- (void)precessTap
{
NSLog(@"点击了黑块!");
[self posstionAnimation];
}
#pragma mark - View Animation
//位移动画(移动到中间的动画)
- (void)posstionAnimation
{
// //开始一个动画
// [UIView beginAnimations:@"position" context:nil];//动画名:position
// //动画的设置
// [UIView setAnimationDuration:0.3]; //设置动画持续时间
// [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; //设置这个动画的变化规律(效果)这里设置为慢入慢出
//
// //动画内容(移动中心点)
//// [UIView setAnimationRepeatAutoreverses:YES];//是否进行逆行执行动画
//// [UIView setAnimationRepeatCount:5];//执行次数
// [UIView setAnimationDelegate:self]; //设置委托对象为自己,让自己再去调用接下来的方法
// [UIView setAnimationDidStopSelector:@selector(stopPossitionAnimation:)];//该动画执行结束后执行的方法
// _blackRect.center = CGPointMake(CGRectGetMidX(self.view.bounds), 280);
//
// //动画开始执行
// [UIView commitAnimations];
//动画block
[UIView animateWithDuration:0.5 animations:^{
//这里写动画效果
_blackRect.center = CGPointMake(CGRectGetMidX(self.view.bounds), 280);
}completion:^(BOOL finished) {
//这里写动画执行完后做什么
[self stopPossitionAnimation:@"position"];
}];
}
//缩放动画
- (void)scaleAnimation
{
[UIView beginAnimations:@"scale" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(stopPossitionAnimation:)];
_blackRect.transform = CGAffineTransformScale(_blackRect.transform, 1.5, 1.5);//放大1.8倍
[UIView commitAnimations];
}
//旋转动画
- (void)rotationAnimation
{
[UIView beginAnimations:@"rotate" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(stopPossitionAnimation:)];
_blackRect.transform = CGAffineTransformRotate(_blackRect.transform, M_PI);//旋转180度
_blackRect.transform = CGAffineTransformRotate(_blackRect.transform, M_PI);//旋转180度
_blackRect.transform = CGAffineTransformRotate(_blackRect.transform, M_PI);//旋转180度
_blackRect.transform = CGAffineTransformRotate(_blackRect.transform, M_PI);//旋转180度
_blackRect.transform = CGAffineTransformRotate(_blackRect.transform, M_PI);//旋转180度
_blackRect.transform = CGAffineTransformRotate(_blackRect.transform, M_PI);//旋转180度
[UIView commitAnimations];
}
//颜色变化动画
- (void)colorChangeAnimation
{
[UIView beginAnimations:@"colorChange" context:nil];
[UIView setAnimationDuration:0.6];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(stopPossitionAnimation:)];
_blackRect.backgroundColor = [UIColor yellowColor];
[UIView commitAnimations];
}
- (void)endAnimation
{
[UIView beginAnimations:@"end" context:nil];
[UIView setAnimationDuration:0.7];
_blackRect.backgroundColor = [UIColor blackColor];
_blackRect.center = CGPointMake(100, 100);
_blackRect.transform = CGAffineTransformIdentity;//变换到原来的大小
// [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:_blackRect cache:NO];//翻页效果
[UIView commitAnimations];
}
- (void)stopPossitionAnimation:(NSString *)animationID
{
NSLog(@"位移动画结束了!");
if ([animationID isEqualToString:@"position"]) {
//位移动画结束后调用缩放动画
[self scaleAnimation];
}else if ([animationID isEqualToString:@"scale"]) {
//缩放动画结束后调用旋转动画
[self rotationAnimation];
}else if ([animationID isEqualToString:@"rotate"]) {
//旋转结束后调用颜色变化动画
[self colorChangeAnimation];
}else if ([animationID isEqualToString:@"colorChange"]) {
//颜色变化后调用结束动画
[self endAnimation];
}
}
@end
0 0
- IOS UI动画与手势的基本使用
- ios 动画的基本使用
- iOS -- 基本的手势
- IOS UI初级-触摸与手势的基本概念和用法
- IOS中UI控件的基本使用
- iOS中的基本 UI 控件的使用
- iOS UI里面五大手势使用
- UI: UIGestureRecognizer IOS中手势的用法
- IOS--UI--LessonGestureRecoginer 手势
- iOS—UI-手势及控件(segment switch slider)的使用
- IOS 开发中手势的基本用法
- iOS的7个基本手势
- IOS各种手势的使用
- iOS拖动手势的使用
- iOS中手势的使用
- iOS UI设计与动画制作
- ios动画中抖动动画效果的实现与CALayer动画的基本理解
- iOS中基本UI控件的介绍和使用
- 常见颜色码值查询
- C++难呀。。。。
- 文本聚类算法分析
- 建议大哥应该精通一门,比如C++
- 1.3000小时左右的自学时间??就算一天1小时
- IOS UI动画与手势的基本使用
- Docker背后的内核知识——Namespace资源隔离
- 算法导论笔记<1>
- php中curl、fsocket、file_get_content三个函数的使用比较
- 不要因为寂寞爱错人,更不要因为爱错人而寂寞
- 转载05:全能程序员学习路线
- 探索 ConcurrentHashMap 高并发性的实现机制
- 输出九九乘法表并输出坐标
- Singleton设计模式