74022

Animating subviews left-right-left

Question:

I want to create a view like the QuickActionBar in Android , which when clicked on a button in top left corner opens simply , but it subviews appears as if they are coming from Right , hit on the left wall , and rebounded back , and then stationed . view is appearing , but i am unable to animate the subviews..

Answer1:

CAKeyframeAnimation looks right for your problem. I have written this animation function before for a label sliding across screen. I updated xValues slightly for your purposes but most probably you will have to play with them. Also after hitting the wall you might want to play with scale.y value you can easily integrate that into keyframe animation.

+ (void) slideAcrossScreen:(UIView *) view Duration:(CGFloat) duration FromLeft:(BOOL) fromLeft { //This is to make it work with both left-right-left and right-left-right anims. CGFloat slideLength = fromLeft ? -view.frame.origin.x : [[UIScreen mainScreen] bounds].size.width - (view.frame.origin.x + view.frame.size.width); CAKeyframeAnimation *anim = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"]; NSArray *xValues = @[[NSNumber numberWithFloat:view.bounds.origin.x], [NSNumber numberWithFloat:view.bounds.origin.x + 10 * slideLength / 10], [NSNumber numberWithFloat:view.bounds.origin.x + 10 * slideLength / 10], [NSNumber numberWithFloat:view.bounds.origin.x + 9 * slideLength / 10]]; [anim setValues:xValues]; NSArray *timeFrames = @[[NSNumber numberWithFloat:0.0], [NSNumber numberWithFloat:0.85], [NSNumber numberWithFloat:0.9], [NSNumber numberWithFloat:1.0]]; [anim setKeyTimes:timeFrames]; [anim setDuration:duration]; [anim setFillMode:kCAFillModeForwards]; [anim setRemovedOnCompletion:FALSE]; [view.layer addAnimation:anim forKey:@"slide"]; }

Answer2:

I just spend 15 minuts in order to resolve your trouble as animating view is always interesting part. So here is snippet, you pass your view to it and it'll animate that. Ofcourse you can add some more to it if you want.

+ (void) animateView : (UIView *) view{ __block CGRect frame = view.frame; frame.origin.x = - 320; [view setFrame:frame]; [UIView animateWithDuration:1.5f animations:^{ frame.origin.x = 10.0f; frame.size.width = 310.0f; [view setFrame:frame]; } completion:^(BOOL finished) { if (finished) { [UIView animateWithDuration:0.5 animations:^{ frame.origin.x = 0.0f; frame.size.width = 320.0f; [view setFrame:frame]; } completion:^(BOOL finished) { }]; } }]; }

Cheers.

Recommend

  • Pause between keyframe animations
  • Translate and scale animation issue
  • Modal box conflict with css key frames
  • Three.js keyframe animation
  • asp.net login page issue
  • BigQuery : is it possible to execute another query inside an UDF?
  • how to get a upsliding caption at bottom for the jquery accordion image slider of kwicks
  • How to push ViewController with slide effect from left to right? Animation name required
  • CouchDB views erroring out
  • web shop (shopping cart) on google app engine
  • IE readonly textarea problem
  • Mockery and Laravel constructor injection
  • Jquery UI Sortable, move item automatically
  • Using SWIG with a build system [closed]
  • PHP multiple file uploads
  • What is the difference between a “service account” and an “installed application”?
  • apply a javascript function to draggable copy
  • Aptana 3 remove bundle (jquery)
  • netsh acl setting (need alternative method - registry settings?)
  • WPF version of .ScaleControl?
  • Application level floating views with navigation in Android
  • blade.php method outputting it's result to the form
  • Clear fused location provider's location for testing
  • AndEngine Applying Transparancy to AndEngine View
  • D3 get axis values on zoom event
  • Using a canvas object in a thread to do simple animations - Java
  • How to revert to previous XCode version?
  • Limiting recursion to certain level - Duplicate rows
  • Avoid links criss cross / overlap in d3.js using force layout
  • Javascript simulate pressing enter in input box
  • recyclerView does not call the onBindViewHolder when scroll in the view
  • Fill an image in a square container while keeping aspect ratio
  • In LanguageTool, how do you create a dictionary and use it for spell checking?
  • Adding custom controls to a full screen movie
  • How to get next/previous record number?
  • Confusion with PayPal's monthly billing cycle
  • EntityFramework adding new object to nested object collection
  • Checking variable from a different class in C#
  • failed to connect to specific WiFi in android programmatically
  • How can I use threading to 'tick' a timer to be accessed by other threads?