美文网首页
UI- --基础动画

UI- --基础动画

作者: 單戈 | 来源:发表于2015-11-11 17:08 被阅读0次

//初始化UIview

_animationView = [[UIView alloc]init];

_animationView.bounds = CGRectMake(0, 0, 200, 200);

_animationView.center = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds));

_animationView.backgroundColor = [UIColor redColor];

[self.view addSubview:_animationView];

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAnimationView:)];

//为_animationView添加单机手势

[_animationView addGestureRecognizer:tapGesture];

//拖动手势

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAnima:)];

[_animationView addGestureRecognizer:pan];

//缩放手势

UIPinchGestureRecognizer *pinchGe = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchGeAnima:)];

[_animationView addGestureRecognizer:pinchGe];

//缩放

- (void)pinchGeAnima:(UIPinchGestureRecognizer *)gesture{

if (gesture.state ==UIGestureRecognizerStateChanged) {

gesture.view.transform = CGAffineTransformScale(gesture.view.transform, gesture.scale,gesture.scale);

//保持缩放系数为1

gesture.scale = 1;

}else if (gesture.state == UIGestureRecognizerStateEnded){

//取消一切形变

//        _animationView.transform = CGAffineTransformIdentity;取消上面的缩放,变回原图

}

}

//拖动

- (void)panAnima:(UIPanGestureRecognizer *)gesture{

if (gesture.state == UIGestureRecognizerStateChanged) {

//拖动方式写这里,获取手势在指定视图的移动坐标

CGPoint transition = [gesture translationInView:self.view];

NSLog(@"%@",NSStringFromCGPoint(transition));

gesture.view.center = CGPointMake(gesture.view.center.x+transition.x, gesture.view.center.y+transition.y);

//重新设置UIGestureRecognizer的增量

[gesture setTranslation:CGPointZero inView:self.view];

}else if(gesture.state == UIGestureRecognizerStateEnded){

}

}

- (void)tapAnimationView:(UITapGestureRecognizer *)gesture{

/**

//--------------------------------1.第一种动画的方式。普通方式

//开始动画

[UIView beginAnimations:nil context:nil];

//设置代理,才能回调动画执行完毕后的方法

[UIView setAnimationDelegate:self];

//设置动画持续时间

[UIView setAnimationDuration:0.5];

//设置动画的线性规律

[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

//设置动画的执行完成后的回调方法

[UIView setAnimationDidStopSelector:@selector(stopAnimating)];

//这里写动画

//改变动画的center

_animationView.center = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds)+150);    //提交动画

[UIView commitAnimations];

**/

/**

//-------------------------------2.第二种执行动画的方式,block

[UIView animateWithDuration:1 animations:^{

_animationView.center = CGPointMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds)+150);

}completion:^(BOOL finished) {//再写个block执行动画回调

_animationView.backgroundColor = [UIColor yellowColor];

}];

**/

//旋转  翻转动画

[self animationvieWithAnimation];

}

//选装翻转动画方法

- (void)animationvieWithAnimation{

[UIView animateKeyframesWithDuration:2 delay:0 options:UIViewKeyframeAnimationOptionAllowUserInteraction animations:^{

//缩放

//        _animationView.transform = CGAffineTransformMakeScale(0.5, 0.5);

//旋转

//        _animationView.transform = CGAffineTransformMakeRotation(M_PI);

//缩放

CGAffineTransform transform = CGAffineTransformMakeScale(0.5, 0.5);

_animationView.transform = CGAffineTransformRotate(transform, M_PI);

//CGAffineTransformRotate保存 了前一个的状态,缩放状态

} completion:^(BOOL finished) {

//翻转

[UIView transitionWithView:_animationView duration:2 options:UIViewAnimationOptionCurveEaseInOut |UIViewAnimationOptionTransitionFlipFromLeft animations:^{

_animationView.backgroundColor = [UIColor blackColor];

} completion:^(BOOL finished) {

}];

}];

}

- (void)stopAnimating{

_animationView.backgroundColor = [UIColor blackColor];

}

相关文章

  • UI- --基础动画

    //初始化UIview _animationView = [[UIView alloc]init]; _anima...

  • 3dMax 制作动画技巧总结

    基本操作 打开默认动画面板:自定义->显示UI->显示轨迹栏 调整帧的密度:Ctrl + Alt + 鼠标右键 切...

  • 3dMax 制作动画技巧总结

    基本操作 打开默认动画面板:自定义->显示UI->显示轨迹栏 调整帧的密度:Ctrl + Alt + 鼠标右键 切...

  • UI-基础控件

    学习UI两天后基本掌握了一些UI的基本控件用法。先说明一下,我学的是iOS 不是IOS,不是ios,也不是IoS等...

  • Android UI-属性动画(二)

    概述 上一篇讲到了属性动画,主要讲到了用法和大概的思路。但是没有讲到具体是如何实现动画的。这里我们分析下View动...

  • Android UI-属性动画(一)

    概述 自定义控件中,如果要做比较好的动画效果,除了理解动画的类型和动画的效果,深入理解动画的原理也是必不可少的一环...

  • Android UI-属性动画(三)

    概述 前两篇已经讲了属性动画的使用和源码的实现。但是大家应该发现了还有非常重要的一部分没有提及,那就是插值器。无论...

  • 为什么我们要使用DTO

    基础结构解释 UI-表现层-与控制器打交道(UI向Controller 传递数据时使用DTO(数据传输对象)) S...

  • 基础动画与关键帧动画

    UIView基础动画一 UIView基础动画二 关键帧动画

  • Android Animation

    Android 动画 标签(空格分隔): android animation 动画基础 Android 基础动画分...

网友评论

      本文标题:UI- --基础动画

      本文链接:https://www.haomeiwen.com/subject/fauhhttx.html