手势,抖动

- (void)loadView
{
    self.view=[[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];
    self.view.backgroundColor=[UIColor whiteColor];
    
    
    _imagView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 20, 100, 200)];
    _imagView.image=[UIImage imageNamed:@"1.png"];
    [self.view addSubview:_imagView];
    [_imagView release];
    
    
    UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.frame=CGRectMake(320-100, 30, 100, 30);
    [btn setTitle:@"ani" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(animationAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    _textField=[[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 30)];
    _textField.borderStyle=UITextBorderStyleRoundedRect;//样式
    [self.view addSubview:_textField];
    [_textField release];
}

-(void)animationAction:(id)sender
{
    
    //动画块开始
    [UIView beginAnimations:nil context:NULL];
    //设置动画时间
        [UIView setAnimationDuration:0.35f];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];//1匀速
  //  [UIView setAnimationRepeatCount:1];
    [UIView setAnimationRepeatCount:MAXFLOAT];
    //设置动画转变方式
//    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:_imagView cache:YES];
    
    
//    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];//2先快后慢
//    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];//3先慢 后快 在慢
//    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];//4先慢后快
    [UIView setAnimationDelegate:self];//设置代理
 //   [UIView setAnimationWillStartSelector:@selector(<#selector#>)];//设置开始代理
    [UIView setAnimationDidStopSelector:@selector(layerAnimation)];//只要设置代理时候使用这个方法 停止代理
    /*
    _imagView.frame=CGRectMake(0, 0, 320, 460);
  //  _imagView.alpha=0.0;
    
   
    
    
    //    [UIView setAnimationBeginsFromCurrentState:NO];
 //   [UIView setAnimationRepeatAutoreverses:YES];
    //    [UIView setAnimationsEnabled:NO];
    */
    //旋转
    /*
    CGAffineTransform newTransFrom=CGAffineTransformRotate(_imagView.transform, M_PI_4);
    _imagView.transform=newTransFrom;
     */
    //缩放
    /*
  //  CGAffineTransform newTrans=CGAffineTransformMakeScale(0.7, 0.7);//缩放 一次
    CGAffineTransform newTrans=CGAffineTransformScale(_imagView.transform, 0.9, 0.9);//在原来的基础上无限缩放
    _imagView.transform=newTrans;
    */
    //位移
 //   CGAffineTransform newTrans=CGAffineTransformMakeTranslation(100, 100);//位移一次
//    CGAffineTransform newTrans=CGAffineTransformTranslate(_imagView.transform, 10, 10);//位移无数次
    

//    _imagView.transform=newTrans;
    
    
 [UIView commitAnimations];    
}

-(void)layerAnimation
{
    /*
    CABasicAnimation*caBasic=[CABasicAnimation animationWithKeyPath:@"opacity"];//opacity 这个是属性不能随便写
    caBasic.fromValue=[NSNumber numberWithInt:1.0];
    caBasic.toValue=[NSNumber numberWithInt:0.0];
    [caBasic setDuration:0.35f];//时间间隔
    [_imagView.layer addAnimation:caBasic forKey:@"ima-opacity"];
    [caBasic setDelegate:self];
    */
    
 //   /*
    CABasicAnimation*caBasic1=[CABasicAnimation animationWithKeyPath:@"bounds.size"];
    caBasic1.fromValue=[NSValue valueWithCGSize:_imagView.bounds.size];
    caBasic1.toValue =[NSValue valueWithCGSize:CGSizeMake(1.0, 1.0)];

    [caBasic1 setDuration:0.35f];//时间间隔
    
    [caBasic1 setDelegate:self];
    [_imagView.layer addAnimation:caBasic1 forKey:@"ima-opacity"];
 //    */
    
    //抖动
    CGPoint c=_textField.center;
    CGPoint lc=CGPointMake(c.x-10, c.y);
    CGPoint rc=CGPointMake(c.x+10, c.y);
    
    CAKeyframeAnimation *keyFrame=[CAKeyframeAnimation animationWithKeyPath:@"position"];
    keyFrame.values=[NSArray arrayWithObjects:[NSValue valueWithCGPoint:c],
                                                [NSValue valueWithCGPoint:lc],
                                                [NSValue valueWithCGPoint:rc],
                                                [NSValue valueWithCGPoint:lc],
                                                [NSValue valueWithCGPoint:rc],
                                                [NSValue valueWithCGPoint:c],nil];
    [keyFrame setDelegate:self];
    [_textField.layer addAnimation:keyFrame forKey:@"textFieldShake"];
    
}
//注意代理的命名方式
- (void)animationDidStart:(CAAnimation *)anim
{
    
}

- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag
{
    //[_imagView.layer removeAllAnimations];
        _textField.textColor=[UIColor redColor];
    _textField.text=@"亲,您输入错误。。。";

}

-(void)animationDisStop
{
        [UIView beginAnimations:nil context:NULL];
    //设置动画时间
    [UIView setAnimationDuration:5.0f];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];//1匀速
//      _imagView.alpha=1.0;
    _imagView.frame=CGRectMake(10, 20, 100, 200);
   

     [UIView commitAnimations];

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值