Facebook open-source animation library POP-small instance, facebookpop-
Instance 1: The image view changes the size with the point on the screen by hand.
-(Void) viewDidLoad {[super viewDidLoad]; // Add the gesture UIPanGestureRecognizer * gesture = [[UIPanGestureRecognizer alloc] init]; [gesture addTarget: self action: @ selector (changeSize :)]; [self. view progress: gesture];}-(void) changeSize :( UIPanGestureRecognizer *) tap {POPSpringAnimation * springAnimation = [POPSpringAnimation progress: kPOPViewFrame]; CGPoint point = [tap locationInView: self. view]; springAnimation. toValue = [NSValue valueWithCGRect: CGRectMake (0, 0, point. x, point. y)]; // elastic value springAnimation. springBounciness = 20.0; // elastic speed springAnimation. springSpeed = 20.0; [_ springView pop_addAnimation: springAnimation forKey: @ "changeframe"];}
Example 2: Achieve a pop-up effect of shrinking the view. The displayed effect is elastic and the effect of shrinking is smaller.
-(Void) viewDidLoad {[super viewDidLoad]; _ showPosition = CGRectMake (320-147, 5,147,160); _ hidePosition = CGRectMake (320, 5, 0, 0 ); _ popView = [[UIImageView alloc] initWithFrame: _ hidePosition]; _ popView. image = [UIImage imageNamed: @ "menu.png"]; [self. view addSubview: _ popView]; self. navigationItem. rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle: @ "+" style: UIBarButtonItemStyleDone target: self action: @ selector (showPop)]; // Let the screen start from the navigation bar (0, 0) if ([self respondsToSelector: @ selector (setEdgesForExtendedLayout :)]) {self. response = UIRectEdgeNone;}-(void) showPop {if (_ isOpened) {[self hidePop]; return;} _ isOpened = YES; POPSpringAnimation * positionAnimation = [POPSpringAnimation progress: kPOPViewFrame]; positionAnimation. fromValue = [NSValue valueWithCGRect: _ hidePosition]; positionAnimation. toValue = [NSValue valueWithCGRect: _ showPosition]; positionAnimation. springBounciness = 15.0f; positionAnimation. springSpeed = 202.16f; [_ popView attributes: positionAnimation forKey: @ "frameAnimation"];}-(void) hidePop {signature * positionAnimation = [Signature attributes: kPOPViewFrame]; positionAnimation. fromValue = [NSValue valueWithCGRect: _ showPosition]; positionAnimation. toValue = [NSValue valueWithCGRect: _ hidePosition]; [_ popView pop_addAnimation: positionAnimation forKey: @ "frameAnimation"]; _ isOpened = NO ;}
Example 3: create two buttons and add two animations. one of the buttons is the animation to change the size and the other is the ViewFrame. You only need to locate the coordinates and the size to make a good animation.
@interface ViewController ()@property (nonatomic, retain) UIView *button;@property (nonatomic, retain) UIView *popOut;@property (readwrite, assign) BOOL timerRunning;@end@implementation ViewController- (void)viewDidLoad{ [super viewDidLoad]; _popOut = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TimerPopOut"]]; [_popOut setFrame:CGRectMake(245, 70, 0, 0)]; [self.view addSubview:_popOut]; _button = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TimerButton"]]; [_button setFrame:CGRectMake(240, 50, 46, 46)]; [self.view addSubview:_button]; _timerRunning = NO; [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(demoAnimate:)]];}- (void)demoAnimate:(UITapGestureRecognizer*)tap{ _timerRunning = !_timerRunning; POPSpringAnimation *buttonAnimation = [POPSpringAnimation animation]; buttonAnimation.property = [POPAnimatableProperty propertyWithName:kPOPLayerSize]; if (_timerRunning) { buttonAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(37, 37)]; } else { buttonAnimation.toValue = [NSValue valueWithCGSize:CGSizeMake(46, 46)]; } buttonAnimation.springBounciness = 10.0; buttonAnimation.springSpeed = 10.0; [_button pop_addAnimation:buttonAnimation forKey:@"pop"]; POPSpringAnimation *popOutAnimation = [POPSpringAnimation animation]; popOutAnimation.property = [POPAnimatableProperty propertyWithName:kPOPViewFrame]; if (!_timerRunning) { popOutAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(245, 70, 0, 10)]; } else { popOutAnimation.toValue = [NSValue valueWithCGRect:CGRectMake(180, 60, 75, 26)]; } popOutAnimation.velocity = [NSValue valueWithCGRect:CGRectMake(200, 0, 300, -200)]; popOutAnimation.springBounciness = 10.0; popOutAnimation.springSpeed = 10.0; [_popOut pop_addAnimation:popOutAnimation forKey:@"slide"];}