文章目录
  1. 1. IOS 实现 UIView 晃动 删除的 效果
  2. 2. IOS 实现 UIView 晃动 删除的 效果

IOS 实现 UIView 晃动 删除的 效果

Ios动画相关 Ios炫丽效果

IOS 实现 UIView 晃动 删除的 效果

// 方法一:

查看文本打印?

  1. //  
  2. //  ViewController.h  
  3. //  text02  
  4. //  
  5. //  Created by YQ - 014 on 9/3/12.  
  6. //  Copyright (c) 2012 YQ - 014. All rights reserved.  
  7. //  
  8. #import <UIKit/UIKit.h>  
  9. @interface ViewController : UIViewController  
  10. @property (retain, nonatomic) IBOutlet UIView *handle;  
  11. @property (retain, nonatomic) IBOutlet UIButton *deleteButton;  
  12. - (IBAction)deletePressed:(id)sender;  
  13. - (IBAction)cancel:(id)sender;  
  14. - (IBAction)buttonPressed:(id)sender;  
  15. @end  
  16. @interface UIView (MyExtension)  
  17. - (void)wobble:(BOOL)wobble;  
  18. @end

  

查看文本打印?

  1. //  
  2. //  ViewController.m  
  3. //  text02  
  4. //  
  5. //  Created by YQ - 014 on 9/3/12.  
  6. //  Copyright (c) 2012 YQ - 014. All rights reserved.  
  7. //  
  8. #import “ViewController.h”  
  9. @implementation  UIView (MyExtension)  
  10. - (void)wobble:(BOOL)wobble  
  11. {  
  12.     if (wobble){   
  13.         self.transform = CGAffineTransformMakeRotation(-0.1);  
  14.         [UIView animateWithDuration:0.12  
  15.                               delay:0.0  
  16.                             options:UIViewAnimationOptionRepeat|UIViewAnimationOptionAutoreverse|UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveLinear  
  17.                          animations:^{      
  18.                              self.transform = CGAffineTransformMakeRotation(0.1);  
  19.                          } completion:nil];  
  20.     }  
  21.     else{  
  22.         [UIView animateWithDuration:0.25  
  23.                               delay:0.0  
  24.                             options:UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseOut  
  25.                          animations:^{  
  26.                              self.transform = CGAffineTransformIdentity;  
  27.                          } completion:nil];  
  28.     }  
  29. }  
  30. @end  
  31. @interface ViewController ()  
  32. @end  
  33. @implementation ViewController  
  34. @synthesize handle;  
  35. @synthesize deleteButton;  
  36. - (void)viewDidLoad  
  37. {  
  38.     [super viewDidLoad];  
  39.     // Do any additional setup after loading the view, typically from a nib.  
  40.     deleteButton.enabled = NO;  
  41.     deleteButton.hidden = YES;  
  42. }  
  43. - (void)viewDidUnload  
  44. {  
  45.     [self setHandle:nil];  
  46.     [self setDeleteButton:nil];  
  47.     [super viewDidUnload];  
  48.     // Release any retained subviews of the main view.  
  49. }  
  50. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation  
  51. {  
  52.     return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);  
  53. }  
  54. - (void)dealloc {  
  55.     [handle release];  
  56.     [deleteButton release];  
  57.     [super dealloc];  
  58. }  
  59. - (IBAction)deletePressed:(id)sender {  
  60.     [self.handle removeFromSuperview];  
  61. }  
  62. - (IBAction)cancel:(id)sender {  
  63.     deleteButton.enabled = NO;  
  64.     deleteButton.hidden = YES;  
  65.     [handle wobble:NO];  
  66. }  
  67. - (IBAction)buttonPressed:(id)sender {  
  68.     deleteButton.hidden = NO;  
  69.     deleteButton.enabled = YES;  
  70.     [handle wobble:YES];  
  71. }  
  72. @end

  

// 方法二:

查看文本打印?

  1. CABasicAnimation *shake = [CABasicAnimation animationWithKeyPath:@”transform”];  
  2.     shake.duration = 0.13;  
  3.     shake.autoreverses = YES;  
  4.     shake.repeatCount = MAXFLOAT;  
  5.     shake.removedOnCompletion = NO;  
  6.     CGFloat rotation = 0.03;  
  7.     shake.fromValue = [NSValue valueWithCATransform3D:CATransform3DRotate(self.layer.transform,-rotation, 0.0 ,0.0 ,1.0)];  
  8.     shake.toValue = [NSValue valueWithCATransform3D:CATransform3DRotate(self.layer.transform, rotation, 0.0 ,0.0 ,1.0)];  
  9.     [self.layer addAnimation:shake forKey:@”shakeAnimation”];

  

// 效果 如下

-102.png

文章目录
  1. 1. IOS 实现 UIView 晃动 删除的 效果
  2. 2. IOS 实现 UIView 晃动 删除的 效果